How many ways I can register the variables into session?How do you define a constant?What is the difference between AIM and SIM in Authorize.Net?If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?How session works (internal processing of session)?How To Get the Uploaded File Information in the Receiving Script?How to increase or decrease the maximum execution time of a php script ?What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?How many ways I can redirect a PHP page?How do I find out the number of parameters passed into function ?How many ways I can register the variables into session?What Is a Session?How to set .htaccess 301 redirection?How to prevent hotlinking in php?How can we destroy the session, how can we unset the variable of a session?What is the difference between Split and Explode in PHP?Would you initialize your strings with single quotes or double quotes?What's PHP ? ~ Interview Questions & Answers

Tuesday, December 15, 2009

How many ways I can register the variables into session?

Global variables in PHP can be registered using the session_register() function. It accepts different number of arguments, any of which can be either a string holding the name of a variable or an array consisting of variable names or other arrays
Example:
Session_register(“simple”);
$_session can also be used for registering variables.
Example:
$_SESSION['count'] = 0;

Wednesday, August 5, 2009

How do you define a constant?

Via define() directive, like define ("MYCONSTANT", 100);

Tuesday, August 4, 2009

What is the difference between AIM and SIM in Authorize.Net?

In SIM (Simple integration Method) customer credit card details are taken on the authorize.net site - no SSL required
AIM (Advanced integration Method) Credit card details are taken over your site SSL require.

please check setup instructions for more details http://www.ecommercetemplates.com/phphelp/ecommplus/authorizenet.asp

Thursday, July 23, 2009

If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?

Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser.

Sunday, July 5, 2009

How session works (internal processing of session)?

To start a session:
– session_start()
– Creates a session identifier
– Session identifier is passed between client and server either as a Cookie, or in GET parameters
Then, can create, access, and modify session variables:
– $_SESSION[session_var_name] = value;
– $_SESSION is only available once you call session_start()
– $local_variable = $_SESSION[session_var_name];
– Can check if session variable is set by using isset();
To end a session:
– session_destroy();

Friday, July 3, 2009

How To Get the Uploaded File Information in the Receiving Script?

Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:
$_FILES[$fieldName]['name'] - The Original file name on the browser system.
$_FILES[$fieldName]['type'] - The file type determined by the browser.
$_FILES[$fieldName]['size'] - The Number of bytes of the file content.
$_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$fieldName]['error'] - The error code associated with this file upload.
The $fieldName is the name used in the .

Tuesday, June 23, 2009

How to increase or decrease the maximum execution time of a php script ?

By default PHP script execution time is set for 30 seconds at php.ini file. This is the time limit set for all the files to finish its execution. If the file takes more than this set time then the execution of the script will be stopped and error message will be displayed like this.
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\test.php on line 10
This maximum execution time limit is set inside the php.ini file like this.
max_execution_time = 30 ; Maximum execution time of each script, in seconds
 
We will use 'time stamp' to find out the delay between starting and ending of a script execution. We will store the 'time stamp' value at the starting of the script and then again we will record at the end of the script . The difference of these two values will give us idea how much time the script has taken to execute. Note that here between two values of time we will try to add some delay by using 'sleep() function'. This sleep function takes numeric value in seconds and delay the execution for that many seconds. We can also create delay by using 'for loop' but this is a better solution. Here is the code.
$t1=time();
sleep(20);
$t2=time(); $t_lapsed=$t2-$t1;
echo "Total time lapsed = $t_lapsed";
We have introduced a delay of 20 seconds and this will execute without any problem, now increase the sleep value to 50 seconds and on execution you will get the error message saying maximum execution time exceeded. This is because by default the maximum execution time set at php.ini is 30 seconds. Now let us change the above code by adding one line set_time_limit(60). Here is the code
set_time_limit ( 60 ) ;
$t1=time(); sleep(50);
$t2=time();
$t_lapsed=$t2-$t1;
echo "Total time lapsed = $t_lapsed";
Now the script will execute fine without any error message. We can see the total time taken by the script.
We can set the time to unlimited value by making it to 0 value. Like this
set_time_limit (0);

Monday, June 22, 2009

What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?

There is at least 3 ways to logon to a remote server:
Use ssh or telnet if you concern with security
You can also use rlogin to logon to a remote server.

Friday, June 5, 2009

How many ways I can redirect a PHP page?

a. Header function in PHP redirects to a new URL
Example:
<?php
header("Location: http://www.redirecturl.com/");
?>
b. http_redirect() is also used to redirect to a new page or URL.
Syntax
void http_redirect ( [string url [, array params [, bool session = FALSE [, int status]]]] )
Here, the URL is the path of the new page. params can be some query parameters followed by whether the session information needs to be passed and the custom response status code.

How do I find out the number of parameters passed into function ?

func_num_args() function returns the number of parameters passed in.

Wednesday, June 3, 2009

How many ways I can register the variables into session?

Global variables in PHP can be registered using the session_register() function. It accepts different number of arguments, any of which can be either a string holding the name of a variable or an array consisting of variable names or other arrays
Example:
Session_register(“simple”);
$_session can also be used for registering variables.
Example:
$_SESSION['count'] = 0;

Tuesday, April 28, 2009

What Is a Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.
There is only one session object available to the PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.
Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

Monday, April 6, 2009

How to set .htaccess 301 redirection?


RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

For more details refer http://www.seobook.com/archives/001714.shtml

Tuesday, February 10, 2009

How to prevent hotlinking in php?

Hotlinking is the act of one site embedding content (such as images, audio files, and videos) hosted on another site. This uses up the ‘bandwidth’ (data transfer allowance) of the site hosting the file, which can be very expensive for webmasters who pay for hosting by the amount of data transferred — as a result, hotlinking is often called ‘leeching’ or ‘bandwidth theft’.
Hotlinking can be prevented using the .htaccess file on an Apache web server, but cheaper web hosting packages often don’t allow webmasters to change this file. The code shown below allows webmasters to prevent hotlinking entirely from within PHP (without .htaccess), which is supported by most web hosting packages. As well as preventing hotlinking the code also allows the site to benefit from direct links (when a site links to content on another site but doesn’t embed it).

How to use the code to prevent hotlinking
1.Create a directory on your website to contain the anti-hotlinking script and your protected media.
2.Copy the code into a file called index.php inside that directory.
3.Replace the URL http://www.example.com/ on the ninth line of the script with the URL of your website — don’t forget to include the trailing slash.
4.Replace the phrase ‘secret-directory-name-here’ in the second line of the script with something people are unlikely to guess (for example, a string of thirty random letters) and create a directory with this name inside the directory containing the script. Do not reveal the name of this secret directory to anyone, as doing so would allow people to hotlink to the files it contains. If you do accidentally reveal the directory name, just rename it and alter the script accordingly.
5.For each piece of content you want to protect, place it in the secret directory (you can also create subdirectories inside that directory).
6.For each piece of content create a file with the same name but with .php appended and place it in the same location as the content. This document should contain HTML (possibly with embedded PHP) to display when a site has either hotlinked or directly linked to yours. The simplest code will redirect the request to the page on your site containing the content:
<?php
header('Location: http://www.example.com/page-containing-the-content/');
?>
7.To include the content in your pages, use a URL of the form http://www.example.com/script-directory/?file=content-file, where ‘script-directory’ is the directory containing the anti-hotlinking script, and ‘content-file’ is the name of the content file (if the content file is in a subdirectory of the secret directory, include the subdirectory in the path — for example ?file=subdirectory/contentfile). These URLs can be included in the pages mentioned in the previous step in order to create a custom page displaying the content instead of redirecting to an existing page on your site.
8.Now when someone tries to hotlink to content on your site, people visiting that page will only see the content if they have already been to your site. Direct links to content on your site will return an HTML file containing the content so you can ensure visitors see the file in its original context.
The script currently includes MIME types for JPEG, PNG, WAV, and MIDI files. If you need to extend it to handle other file types, look up the MIME type name in the official list of MIME types and then add code of the following form above the line containing 'jpg'=>'image/jpeg',:
'extenstion'=>'mimetype',‘extension’ is the file extension (for example, ‘mpg’) and ‘mimetype’ is the official MIME type (for example, ‘video/mpeg’). Some formats do not have registered MIME types, in which case the x prefix should be used (for example, ‘image/x-myimageformat’).
How the code to prevent hotlinking works
1 <?php
2 $dir='secret-directory-name-here/';
3 if ((!$file=realpath($dir.$_GET['file']))
4 || strpos($file,realpath($dir))!==0 || substr($file,-4)=='.php'){
5 header('HTTP/1.0 404 Not Found');
6 exit();
7 }
8 $ref=$_SERVER['HTTP_REFERER'];
9 if (strpos($ref,'http://www.example.com/')===0 || strpos($ref,'http')!==0){
10 $mime=array(
11 'jpg'=>'image/jpeg',
12 'png'=>'image/png',
13 'mid'=>'audio/x-midi',
14 'wav'=>'audio/x-wav'
15 );
16 $stat=stat($file);
17 header('Content-Type: '.$mime[substr($file,-3)]);
18 header('Content-Length: '.$stat[7]);
19 header('Last-Modified: '.gmdate('D, d M Y H:i:s',$stat[9]).' GMT');
20 readfile($file);
21 exit();
22 }
23 header('Pragma: no-cache');
24 header('Cache-Control: no-cache, no-store, must-revalidate');
25 include($file.'.php');
26 ?>
Line 2
Line 2 stores the name of secret directory so that the script can easily be modified.
Lines 3 to 7
On line 3, the first condition of the if-test checks that the file exists and resolves any relative path components (for exmaple ../). On line 4, the second condition checks the the path specified is in the secret directory (so that people can’t use relative path components to see the source code of scripts on your site), and the third condition checks that the path does not refer to one of the PHP files associated with the content. If the file specified should not be accessed (or doesn’t exist) a 404 (file not found) status code is returned and the script exits.
Lines 8 and 9
The if-test in line 9 could have been written in various forms, but using the ‘or’ operator with this order of parameters is fastest. The test allows the file to be displayed if either the referrer header does not refer to a website (for example, a blank refer or one obscured by security software), or if it refers to the correct wesbite. The slash at the end of the website name is necessary to prevent exploitation by websites with names of the form http://www.yoursite.com.theirsite.com/), and the use of ‘http’ in the second condition catches both regular (http://) and secure (https://) referrers.
Lines 19 to 21
These lines output the content file with the appropriate headers for content type, content length, and date of last modification, and then exit the script.
Lines 23 to 25
These lines output headers to prevent caching and then perform the action specified in the PHP file associated with the content file (for example, redirecting to the page containing the content). The anti-caching headers are needed so that if users later try to view the content as you intended they will receive the content file and not the HTML file. Note that the content file itself will be cached, which means that if a site hotlinks to the file and a user already has the file in their cache they will still see it. If they don’t already have the file in their cache, their browser will download an HTML file, which it will realise isn’t a media file and won’t display (unless the link was a direct link, rather than a hotlink).

How can we destroy the session, how can we unset the variable of a session?

session_unset() function frees all session variables currently registered.
If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable.
i.e. unset ($_SESSION['varname']);.

What is the difference between Split and Explode in PHP?

The split() function splits the string into an array using a regular expression and returns an array.
Ex: split(":","India:Pakistan:Srilanka"); returns an array that contains India, Pakistan, Srilanka.
The explode() function splits the string by string.
Ex: explode("and", "India and Pakistan and Srilanka"); returns an array that contains India, Pakistan, Srilanka.
split() function is deprecated as of php5.3.0 . Use preg_split instead of split().

Monday, February 9, 2009

Would you initialize your strings with single quotes or double quotes?

Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

What's PHP ?

The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.