How can we access the data sent through the URL with the GET method?
To access the data sent via the GET method, we use $_GET array like this:
www.url.com?var=value
$variable = $_GET["var"]; this will now contain 'value'
How can we access the data sent through the URL with the POST method?
To access the data sent this way, you use the $_POST array.
Imagine you have a form field called 'var' on the form when the user clicks submit to the post form, you can then access the value like this:
$_POST["var"];
What Is The Timeout Period On Session Values?
The PHP engine has no direct settings on session timeout period. But it has a session garbage collection mechanism that you can set to remove those special files containing session values. There are 3 settings you can use to define the session garbage collection mechanism:
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
The first two settings tell the PHP engine to run the garbage collection process once every 1000 requests received by the Web server. The last setting tells the PHP engine to treat session values as garbage 1440 seconds after they have not been used.
Putting all settings together, your session values probably be removed 1440 seconds after the visitor stopping using your Web site. The probability of this removal is one over 1000 requests received after the 1440-second period.
In another word, if visitor John stopped using your site, and there is no other visitors coming to your site, session values created for John will never be removed. However, if you have a busy site, like 1000 requests per minute, John's session values will be removed about one minute plus 1440 seconds after John stopped using the site.
How To Set Session.gc_maxlifetime Properly?
As you know that session.gc_maxlifetime is the session value timeout period. You should set this value based on the usage pattern of your visitors. Here are some suggestions:
# Set it to 20 minutes for a normal Web site:
session.gc_maxlifetime = 1200
# Set it to 24 hours if visitors comes to the site many time a day:
# Example: Yahoo email site expires your session in 24 hours.
session.gc_maxlifetime = 86400
How To Set Session.gc_divisor Properly?
As you know that session.gc_divisor is the frequency of when the session garbage collection process will be executed. You should set this value based on the income request traffic. Here are some suggestions:
# Set it to 10, if traffic is less than 10,000 per day:
session.gc_divisor = 10
# Set it to 100, if traffic is between 10,000 and 100,000 per day:
session.gc_divisor = 100
# Set it to 1000, if traffic is greater than 100,000 per day:
session.gc_divisor = 1000
How To Remove Values Saved In The Current Session?
If you want to remove values saved in the current session, you should use the unset() function on those saved values in $_SESSION, or use array() to empty $_SESSION:
unset($_SESSION['MyColor']) - Removes one value named MyColor in the current session.
$_SESSION = array() - Removes all values in the current session.
unset($_SESSION) - Bad statement. It may affect the session mechanism.
What's The Difference Between Include And Require?
It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
Steps For The Payment Gateway Processing?
An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer’s credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching.
Can We Use Include(abc.php) Two Times In A Php Page Makeit.php?
Yes we can include that many times we want, but here are some things to make sure of: (including abc.PHP, the file names are case-sensitive).
there shouldn't be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php.
How Many Ways We Can Give The Output To A Browser?
HTML output
PHP, ASP, JSP, Servlet Function
Script Language output Function
Different Type of embedded Package to output to a browser.
Which Method Do You Follow To Get A Record From A Million Records? (searching Not From Database, From An Array In Php)?
use array_searchfl, array_keys, arrayyalues, array_key_exists, and in_array.
Are Namespaces Are There In Javascript?
A namespace is a container and allows you to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you’ve attached all further methods, properties and objects. But it is not always necessary to use namespace.
What Is 'float' Property In Css?
The float property sets where an image or a text will appear in another element.
What Are The Advantages/disadvantages Of Mysql And Php?
Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and iSP.
What Are The File Upload Settings In Configuration File?
There are several settings in the PHP configuration file related to file uploading:
• file_uploads = On/Off - Whether or not to allow HTTP file uploads.
• upload_tmp_dir = directory - The temporary directory used for storing files when doing file upload.
• upload_max_filesize = size - The maximum size of an uploaded file.
How Many Escape Sequences Are Recognized In Double-quoted Strings?
There are 12 escape sequences you can use in double-quoted strings:
• \\ - Represents the back slash character.
• \" - Represents the double quote character.
• \$ - Represents the dollar sign.
• \n - Represents the new line character (ASCII code 10).
• \r - Represents the carriage return character (ASCII code 13).
• \t - Represents the tab character (ASCII code 9).
• \{ - Represents the open brace character.
• \} - Represents the close brace character.
• \[ - Represents the open bracket character.
• \] - Represents the close bracket character.
• \nnn - Represents a character as an octal value.
• \xnn - Represents a character as a hex value.
How To Include Variables In Double-quoted Strings?
Variables included in double-quoted strings will be interpolated. Their values will be concatenated into the enclosing strings. For example, two statements in the following PHP script will print out the same string:
<?php
$variable = "and";
echo "part 1 $variable part 2\n";
echo "part 1 ".$variable." part 2\n";
?>
This script will print:
part 1 and part 2
part 1 and part 2
How To Uploaded Files To A Table?
To store uploaded files to MySQL database, you can use the normal SELECT statement as shown in the modified processing_uploaded_files.php listed below:
<?php
$con = mysql_connect("localhost", "", "");
mysql_select_db("pickzy");
$error = $_FILES['pickzycenter_logo']['error'];
$tmp_name = $_FILES['pickzycenter_logo']['tmp_name'];
$size = $_FILES['pickzycenter_logo']['size'];
$name = $_FILES['pickzycenter_logo']['name'];
$type = $_FILES['pickzycenter_logo']['type'];
print("
\n");
if ($error == UPLOAD_ERR_OK && $size > 0) {
$fp = fopen($tmp_name, 'r');
$content = fread($fp, $size);
fclose($fp);
$content = addslashes($content);
$sql = "INSERT INTO pickzy_files (name, type, size, content)"
. " VALUES ('$name', '$type', $size, '$content')";
mysql_query($sql, $con);
print("File stored.\n");
} else {
print("Upload faield.\n");
}
print("
\n");
mysql_close($con);
?>
Note that addslashes() is used to add backslashes to special characters that need to be protected in SQL statements.
How To Create A Table To Store Files?
If you using MySQL database and want to store files in database, you need to create BLOB columns, which can holds up to 65,535 characters. Here is a sample script that creates a table with a BLOB column to be used to store uploaded files:
<?php
$con = mysql_connect("localhost", "", "");
mysql_select_db("pickzy");
$sql = "CREATE TABLE pickzy_files ("
. " id INTEGER NOT NULL AUTO_INCREMENT"
. ", name VARCHAR(80) NOT NULL"
. ", type VARCHAR(80) NOT NULL"
. ", size INTEGER NOT NULL"
. ", content BLOB"
. ", PRIMARY KEY (id)"
. ")";
mysql_query($sql, $con);
mysql_close($con);
?>
Why Do You Need To Filter Out Empty Files?
When you are processing uploaded files, you need to check for empty files, because they could be resulted from a bad upload process but the PHP engine could still give no error.
For example, if a user typed a bad file name in the upload field and submitted the form, the PHP engine will take it as an empty file without raising any error. The script below shows you an improved logic to process uploaded files:
<?php
$file = '\pickzycenter\images\pickzycenter.logo';
$error = $_FILES['pickzycenter_logo']['error'];
$tmp_name = $_FILES['pickzycenter_logo']['tmp_name'];
print("
\n");
if ($error==UPLOAD_ERR_OK) {
if ($_FILES['pickzycenter_logo']['size'] > 0) {
move_uploaded_file($tmp_name, $file);
print("File uploaded.\n");
} else {
print("Loaded file is empty.\n");
}
} else if ($error==UPLOAD_ERR_NO_FILE) {
print("No files specified.\n");
} else {
print("Upload faield.\n");
}
print("
\n");
?>
How To Move Uploaded Files To Permanent Directory?
PHP stores uploaded files in a temporary directory with temporary file names. You must move uploaded files to a permanent directory, if you want to keep them permanently.
PHP offers the move_uploaded_file() to help you moving uploaded files. The example script, processing_ uploaded_files.php, below shows a good example:
<?php
$file = '\pickzycenter\images\pickzycenter.logo';
print("<pre>\n");
move_uploaded_file($_FILES['pickzycenter_logo']['tmp_name'], $file);
print("File uploaded: ".$file."\n");
print("</pre>\n");
?>
Note that you need to change the permanent directory, "\pickzycenter\images\", used in this script to something else on your Web server. If your Web server is provided by a Web hosting company, you may need to ask them which directories you can use to store files.
If you copy both scripts, logo_upload.php and processing_uploaded_files.php, to your Web server, you can try them to upload an image file to your Web server.
To access the data sent via the GET method, we use $_GET array like this:
www.url.com?var=value
$variable = $_GET["var"]; this will now contain 'value'
How can we access the data sent through the URL with the POST method?
To access the data sent this way, you use the $_POST array.
Imagine you have a form field called 'var' on the form when the user clicks submit to the post form, you can then access the value like this:
$_POST["var"];
What Is The Timeout Period On Session Values?
The PHP engine has no direct settings on session timeout period. But it has a session garbage collection mechanism that you can set to remove those special files containing session values. There are 3 settings you can use to define the session garbage collection mechanism:
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
The first two settings tell the PHP engine to run the garbage collection process once every 1000 requests received by the Web server. The last setting tells the PHP engine to treat session values as garbage 1440 seconds after they have not been used.
Putting all settings together, your session values probably be removed 1440 seconds after the visitor stopping using your Web site. The probability of this removal is one over 1000 requests received after the 1440-second period.
In another word, if visitor John stopped using your site, and there is no other visitors coming to your site, session values created for John will never be removed. However, if you have a busy site, like 1000 requests per minute, John's session values will be removed about one minute plus 1440 seconds after John stopped using the site.
How To Set Session.gc_maxlifetime Properly?
As you know that session.gc_maxlifetime is the session value timeout period. You should set this value based on the usage pattern of your visitors. Here are some suggestions:
# Set it to 20 minutes for a normal Web site:
session.gc_maxlifetime = 1200
# Set it to 24 hours if visitors comes to the site many time a day:
# Example: Yahoo email site expires your session in 24 hours.
session.gc_maxlifetime = 86400
Baidu Most Frequently Asked Latest PHP Interview Questions Answers |
How To Set Session.gc_divisor Properly?
As you know that session.gc_divisor is the frequency of when the session garbage collection process will be executed. You should set this value based on the income request traffic. Here are some suggestions:
# Set it to 10, if traffic is less than 10,000 per day:
session.gc_divisor = 10
# Set it to 100, if traffic is between 10,000 and 100,000 per day:
session.gc_divisor = 100
# Set it to 1000, if traffic is greater than 100,000 per day:
session.gc_divisor = 1000
How To Remove Values Saved In The Current Session?
If you want to remove values saved in the current session, you should use the unset() function on those saved values in $_SESSION, or use array() to empty $_SESSION:
unset($_SESSION['MyColor']) - Removes one value named MyColor in the current session.
$_SESSION = array() - Removes all values in the current session.
unset($_SESSION) - Bad statement. It may affect the session mechanism.
What's The Difference Between Include And Require?
It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
Steps For The Payment Gateway Processing?
An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer’s credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching.
Can We Use Include(abc.php) Two Times In A Php Page Makeit.php?
Yes we can include that many times we want, but here are some things to make sure of: (including abc.PHP, the file names are case-sensitive).
there shouldn't be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php.
How Many Ways We Can Give The Output To A Browser?
HTML output
PHP, ASP, JSP, Servlet Function
Script Language output Function
Different Type of embedded Package to output to a browser.
Which Method Do You Follow To Get A Record From A Million Records? (searching Not From Database, From An Array In Php)?
use array_searchfl, array_keys, arrayyalues, array_key_exists, and in_array.
Are Namespaces Are There In Javascript?
A namespace is a container and allows you to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you’ve attached all further methods, properties and objects. But it is not always necessary to use namespace.
What Is 'float' Property In Css?
The float property sets where an image or a text will appear in another element.
What Are The Advantages/disadvantages Of Mysql And Php?
Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and iSP.
What Are The File Upload Settings In Configuration File?
There are several settings in the PHP configuration file related to file uploading:
• file_uploads = On/Off - Whether or not to allow HTTP file uploads.
• upload_tmp_dir = directory - The temporary directory used for storing files when doing file upload.
• upload_max_filesize = size - The maximum size of an uploaded file.
How Many Escape Sequences Are Recognized In Double-quoted Strings?
There are 12 escape sequences you can use in double-quoted strings:
• \\ - Represents the back slash character.
• \" - Represents the double quote character.
• \$ - Represents the dollar sign.
• \n - Represents the new line character (ASCII code 10).
• \r - Represents the carriage return character (ASCII code 13).
• \t - Represents the tab character (ASCII code 9).
• \{ - Represents the open brace character.
• \} - Represents the close brace character.
• \[ - Represents the open bracket character.
• \] - Represents the close bracket character.
• \nnn - Represents a character as an octal value.
• \xnn - Represents a character as a hex value.
How To Include Variables In Double-quoted Strings?
Variables included in double-quoted strings will be interpolated. Their values will be concatenated into the enclosing strings. For example, two statements in the following PHP script will print out the same string:
<?php
$variable = "and";
echo "part 1 $variable part 2\n";
echo "part 1 ".$variable." part 2\n";
?>
This script will print:
part 1 and part 2
part 1 and part 2
How To Uploaded Files To A Table?
To store uploaded files to MySQL database, you can use the normal SELECT statement as shown in the modified processing_uploaded_files.php listed below:
<?php
$con = mysql_connect("localhost", "", "");
mysql_select_db("pickzy");
$error = $_FILES['pickzycenter_logo']['error'];
$tmp_name = $_FILES['pickzycenter_logo']['tmp_name'];
$size = $_FILES['pickzycenter_logo']['size'];
$name = $_FILES['pickzycenter_logo']['name'];
$type = $_FILES['pickzycenter_logo']['type'];
print("
\n");
if ($error == UPLOAD_ERR_OK && $size > 0) {
$fp = fopen($tmp_name, 'r');
$content = fread($fp, $size);
fclose($fp);
$content = addslashes($content);
$sql = "INSERT INTO pickzy_files (name, type, size, content)"
. " VALUES ('$name', '$type', $size, '$content')";
mysql_query($sql, $con);
print("File stored.\n");
} else {
print("Upload faield.\n");
}
print("
\n");
mysql_close($con);
?>
Note that addslashes() is used to add backslashes to special characters that need to be protected in SQL statements.
How To Create A Table To Store Files?
If you using MySQL database and want to store files in database, you need to create BLOB columns, which can holds up to 65,535 characters. Here is a sample script that creates a table with a BLOB column to be used to store uploaded files:
<?php
$con = mysql_connect("localhost", "", "");
mysql_select_db("pickzy");
$sql = "CREATE TABLE pickzy_files ("
. " id INTEGER NOT NULL AUTO_INCREMENT"
. ", name VARCHAR(80) NOT NULL"
. ", type VARCHAR(80) NOT NULL"
. ", size INTEGER NOT NULL"
. ", content BLOB"
. ", PRIMARY KEY (id)"
. ")";
mysql_query($sql, $con);
mysql_close($con);
?>
Why Do You Need To Filter Out Empty Files?
When you are processing uploaded files, you need to check for empty files, because they could be resulted from a bad upload process but the PHP engine could still give no error.
For example, if a user typed a bad file name in the upload field and submitted the form, the PHP engine will take it as an empty file without raising any error. The script below shows you an improved logic to process uploaded files:
<?php
$file = '\pickzycenter\images\pickzycenter.logo';
$error = $_FILES['pickzycenter_logo']['error'];
$tmp_name = $_FILES['pickzycenter_logo']['tmp_name'];
print("
\n");
if ($error==UPLOAD_ERR_OK) {
if ($_FILES['pickzycenter_logo']['size'] > 0) {
move_uploaded_file($tmp_name, $file);
print("File uploaded.\n");
} else {
print("Loaded file is empty.\n");
}
} else if ($error==UPLOAD_ERR_NO_FILE) {
print("No files specified.\n");
} else {
print("Upload faield.\n");
}
print("
\n");
?>
How To Move Uploaded Files To Permanent Directory?
PHP stores uploaded files in a temporary directory with temporary file names. You must move uploaded files to a permanent directory, if you want to keep them permanently.
PHP offers the move_uploaded_file() to help you moving uploaded files. The example script, processing_ uploaded_files.php, below shows a good example:
<?php
$file = '\pickzycenter\images\pickzycenter.logo';
print("<pre>\n");
move_uploaded_file($_FILES['pickzycenter_logo']['tmp_name'], $file);
print("File uploaded: ".$file."\n");
print("</pre>\n");
?>
Note that you need to change the permanent directory, "\pickzycenter\images\", used in this script to something else on your Web server. If your Web server is provided by a Web hosting company, you may need to ask them which directories you can use to store files.
If you copy both scripts, logo_upload.php and processing_uploaded_files.php, to your Web server, you can try them to upload an image file to your Web server.
Post a Comment