By Sergey Skudaev
Let us try to use $_COOKIE[ ] variable.
Edit form_methods.php and add the following piece of code. The cookie´s code must be inserted before HTML header. Other wise you will get error! The setcookie function will set $pref variable to $_COOKIE[] variable.
<?
$pref="Mrs";
setcookie("prefix",$pref);
?>
<html>
<head>
<title>Form Methods
</title>
</head>
<body>
<form method="post" action="formoutputpage.php">
<p><input type=text name=greeting size="15"></p>
<p><input type=text name=name size="15"></p>
<p><input type=submit name=submit value="Salutation"></p>
</form>
</body>
</html>
Edit formoutputpage.php file like that:
<?
echo $_POST['greeting'];
echo " ".$_COOKIE['prefix'];
echo " ".$_POST['name'];
?>
The output page displays
Hello Mrs. Emily.
Let us try to use session variable. The session´s code must be inserted before HTML header. Other wise you will get error! Edit form_methods.php file:
<?
session_start();
$_SESSION['title']="Dr.";
setcookie("prefix","Mrs");
?>
<html>
<head>
<title>Form Methods
</title>
</head>
<body>
<form method="post" action="formoutputpage.php">
<p><input type=text name=greeting size="15"></p>
<p><input type=text name=name size="15"></p>
<p><input type=submit name=submit value="Salutation"></p>
</form>
</body>
</html>
Edit formoutputpage.php file.The session_start() function starts session. It must be used each time you assign value to $_SESSION variable or read value from $_SESSION variable.
<?
session_start();
echo $_POST['greeting'];
echo " ".$_SESSION['title'];
echo " ".$_COOKIE['prefix'];
echo " ".$_POST['name'];
?>
The output page will display:
Hello Dr. Mrs. Emily
You can transfer data from one page to another via link. Edit form_methods.php file. Date sent by link is transfered by get method. It can be read from $_GET[] variable
<?
session_start();
$_SESSION['title']="Dr.";
setcookie("prefix","Mrs");
?>
<html>
<head>
<title>Form Methods
</title>
</head>
<body>
<form method="post" action="formoutputpage.php">
<p><input type=text name=greeting size="15"></p>
<p><input type=text name=name size="15"></p>
<p><input type=submit name=submit value="Salutation"></p>
</form>
<?
$greeting="Good morning"
$person="Michael";
print('<p><a href="link_output.php?greeting='.$greeting.'&person='.$person.'">Link output</a>');
?>
</body>
</html>
When you hover mouse over the link, $GET variables are displayed on the browser task bar.
Create link_output.php file.
<?
$greeting=$_GET['greeting'];
$person=$_GET['person'];
echo $greeting." ".$person."!";
?>
Click the link of form_methods.php page and you will the output:
Good morning Michael!
You can use $_REQUEST[] variable that contains contents of $_GET, $_POST and $_COOKIE variables. Edit formoutputpage.php.
<?
session_start();
echo $_REQUEST['greeting'];
echo " ".$_SESSION['title'];
echo " ".$_REQUEST['prefix'];
echo " ".$_REQUEST['name'];
?>
Fill the form and submit. Output will be the same: Hello Dr. Mrs. Emily!
Also you can insert statement import_request_variables("pgc",""); and use form input field names to access $_GET[], $_POST[] and $_COOKIE[]
Edit formoutputpage.php file like that:
<?
import_request_variables("pgc","");
session_start();
echo $greeting;
echo " ".$_SESSION['title'];
echo " ".$prefix;
echo " ".$name;
?>
Submit form again and you will get the same output: Hello Dr. Mrs. Emily!
Click link on the form and you will get output: Good morning Michael!
User Authorization with Session Cookies
Our dog needs urgent surgery, and the cost is overwhelming.
Any help, big or small, would mean the world to us. Thank you for supporting Oscar on his journey to recovery!
Oscar Story.
Oscar wasn’t just any puppy—he was a gift from a mother who trusted us with her smallest one.
For five years, my wife worked at the Indian Medical Center in Arizona, deep in Navajo Nation. Near her clinic, she often saw a homeless dog wandering the area. Over time, she began feeding her, and the dog grew fond of her. Then, one day, that same dog brought her newborn puppies to my wife—as if proudly showing them off.
Among them was the smallest, most delicate pup. My wife couldn’t resist. She brought him home, and we named him Oscar.
Oscar thrived in the house provided by the medical center, enjoying the big backyard where he lived. I built him a sturdy wooden doghouse, and we often took him on walks along the Window Rock Trail. He became our adventure companion, making the vast desert feel like home.
After my wife’s contract ended, we moved back to Florida, bringing Oscar with us. He adjusted to his new surroundings, but he never lost his adventurous spirit.
Now, Oscar faces a tough challenge—he needs urgent surgery, and the cost is overwhelming. We want to give him the best care possible, just as he’s given us years of joy and loyalty.
Any help, big or small, would mean the world to us. Thank you for supporting Oscar on his journey to recovery!