Accessing data from a simple POST HTML form

advertisement
Types
Four scalar types: boolean ,integer ,floating-point number (float) ,string
Two compound types: array ,object
And finally two special types: resource ,NULL
This manual also introduces some pseudo-types for readability reasons:
mixed ,number ,callback
$bool = TRUE;
$str = "foo";
$int = 12;
// a boolean
// a string
// an integer
gettype -- Get the type of a variable (str,int,boolean)
settype -- Set the type of a variable
bool function_exists ( string function_name)
bool method_exists ( object object, string method_name)
PHP Superglobals
$GLOBALS Contains a reference to every variable which is currently available within
the global scope of the script. The keys of this array are the names of the global variables.
$GLOBALS has existed since PHP 3.
$_SERVER Variables set by the web server or otherwise directly related to the execution
environment of the current script. Analogous to the old $HTTP_SERVER_VARS array
(which is still available, but deprecated).
$_GET Variables provided to the script via HTTP GET. Analogous to the old
$HTTP_GET_VARS array (which is still available, but deprecated).
$_POST Variables provided to the script via HTTP POST. Analogous to the old
$HTTP_POST_VARS array (which is still available, but deprecated).
$_COOKIE Variables provided to the script via HTTP cookies. Analogous to the old
$HTTP_COOKIE_VARS array (which is still available, but deprecated).
$_FILES Variables provided to the script via HTTP post file uploads. Analogous to the
old $HTTP_POST_FILES array (which is still available, but deprecated). See POST method
uploads for more information.
$_ENV Variables provided to the script via the environment. Analogous to the old
$HTTP_ENV_VARS array (which is still available, but deprecated).
$_REQUEST Variables provided to the script via any user input mechanism, and which
therefore cannot be trusted. The presence and order of variable inclusion in this array is
defined according to the variables_order configuration directive. This array has no direct
analogue in versions of PHP prior to
define("CONSTANT", "Hello world.");
include(). require() and include() are identical
The include() statement includes and evaluates the specified file.
The documentation below also applies to require().
include() produces a Warning
while require() results in a Fatal Error.
In other words, use require() if you want a missing file to halt processing of
the page.
include() does not behave this way, the script will continue regardless. Be
sure to have an appropriate
include_path setting as well. When a file is included, the code it contains
inherits the variable scope of the line on which the include occurs. Any
variables available at that line in the calling file will be available within the
called file, from that point forward.
The require_once() statement includes and evaluates the specified file during the
execution of the script. This is a behavior similar to the require() statement, with the only
difference being that if the code from a file has already been included, it will not be
included again. See the documentation for require() for more information on how this
statement works.
require_once() should be used in cases where the same file might be included and
evaluated more than once during a particular execution of a script, and you want to be
sure that it is included exactly once to avoid problems with function redefinitions,
variable value reassignments, etc.
require_once("a.php"); // this will include a.php
require_once("A.php"); // this will include a.php again on Windows!
The include_once() statement includes and evaluates the specified file during the
execution of the script. This is a behavior similar to the include() statement, with the only
difference being that if the code from a file has already been included, it will not be
included again. As the name suggests, it will be included just once.
include_once() should be used in cases where the same file might be included and
evaluated more than once during a particular execution of a script, and you want to be
sure that it is included exactly once to avoid problems with function redefinitions,
variable value reassignments, etc.
get_required_files -- Returns an array with the names of included or required files
get_included_files -- Returns an array with the names of included or required files
max_execution_time = 30 seconds
Accessing data from a simple POST HTML form
print $_POST['username'];
print $_REQUEST['username'];
print $HTTP_POST_VARS['username'];
import_request_variables(‘p’,’p_’);
Setting Cookies
$count++;
setcookie("count", $count, time()+3600);
<?php
$filename = "/var/www/html/admin/adtariff_note1111111.txt";
if (file_exists($filename))
{
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
echo $contents;
}
else
{
print "The file $filename does not exist";
}
fclose ($fd);
?>
Diff bet echo and Print
The other one is that you can pass more expression to **echo** (but do not use the parentheses)
whereas you can only pass one at a time with **print**:
There's a subtle difference between print() and echo. print() is a function, echo is a language
construct. So this will work:
$some_boolean ? print("true") : print("false");
but this won't:
$some_boolean ? echo("true") : echo("false");
There is a difference between the two, but speed-wise it
should be irrelevant which one you use. print() behaves
like a function in that you can do:
$ret = print "Hello World";
And $ret will be 1
That means that print can be used as part of a more complex
expression where echo cannot. print is also part of the
precedence table which it needs to be if it is to be used
within a complex expression. It is just about at the bottom
of the precendence list though. Only "," AND, OR and XOR
are lower.
echo is marginally faster since it doesn't set a return
value if you really want to get down to the nitty gritty.
If the grammar is:
echo expression [, expression[, expression] ... ]
Then
echo ( expression, expression )
is not valid. ( expression ) reduces to just an expression
so this would be valid:
echo ("howdy"),("partner");
but you would simply write this as:
echo "howdy","partner";
if you wanted to use two expression. Putting the brackets
in there serves no purpose since there is no operator
precendence issue with a single expression like that.
Download