PHP Imp
PHP Imp
What is PHP?
What is difference between “echo” and “print”?
What is the use of isset ( ) function?
Which are the methods to submit form?
Explain setcookie ( ) in PHP.
What is $-SESSION in PHP?
Explain split ( ) function in PHP.
4 marks
Some predefined variables in PHP are "superglobals", which means that they
are always accessible, regardless of scope - and you can access them from
any function, class or file without having to do anything special.
$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION
$_GET : $_GET is a super global variable used to collect data from the
HTML form after submitting it. When form uses method get to
transfer data, the data is visible in the query string, therefore the
values are not hidden. $_GET super global array variable stores the
values that come in the URL.
Syntax:
get_browser(user_agent, return_array)
A common use of PHP_SELF variable is in the action field of the <form> tag.
The action field of the FORM instructs where to submit the form data when
the user presses the “submit” button. It is common to have the same PHP
page as the handler for the form as well.
However, if you provide the name of the file in the action field, in case you
happened to rename the file, you need to update the action field as well; or
your forms will stop working.
Using PHP_SELF variable you can write more generic code which can be used
on any page and you do not need to edit the action field.
Consider, you have a file called form-action.php and want to load the same
page after the form is submitted. The usual form code will be:
Here is the combined code, that contains both the form and the PHP script.
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name
</b>";
echo "<br>You can use the following form again to enter a new name.";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>
<?php
function generate_pw() {
$pw = '';
return $pw;
?>
3 marks