I came up with a basic sessions example to work off of and I havent touched it in forever and wanted some feedback on it:
index.php
<?
if(empty($_POST['data']))
{
echo "Give me session data:";
echo "<form action=\"index.php\" method=\"post\">";
echo "<input type=\"text\" name=\"data\" id=\"data\" />";
echo "<input type=\"submit\" name\"Post\" value=\"Post\" /></form>";
}
else
{
if (!session_id()) { session_start(); }
$_SESSION["sess_var"]=$_POST['data'];
echo "Session Created: <br />";
echo "The content of \$sess_var is " . $_SESSION['sess_var'] . "<br /><a href=\"page2.php\">Next</a>";
}
?>
page2.php
<?
if (!session_id()) { session_start(); }
if (!$_SESSION['sess_var']) { header("Location: index.php"); }
echo "Session Carries Over: <br />";
echo "The content of \$sess_var is " . $_SESSION['sess_var'] . "<br />";
?>
<a href="page3.php">Next</a>
page3.php
<?
if (!session_id()) { session_start(); }
if (!$_SESSION['sess_var']) { header("Location: index.php"); }
echo "Session is Unset: <br />";
unset($_SESSION['sess_var']);
echo "Session is Destroyed: <br />";
session_destroy();
?>
<a href="index.php">Start Over</a>
does that look about right or is there a better way todo things?
my goal here; at least for this project coming up (shoping cart) is to just have an authed session across the cart pages (or maybe the entire site)
at any rate, any feedback is welcomed 🙂
thanks