weronpc
04-09-2003, 09:09 PM
Hello,
I went to php.net and read the section about session. I have some basic idea what is session about, but not fully understand it.
Can someone write me a simple script on how to use session? I just want to know what are some benefits of using session.
Thank you so much,
Mike
Nightfire
04-09-2003, 10:07 PM
nice simple example.
form.php
<?
if(!isset($_POST['submit'])){
// form hasn't been submitted yet, so show the form
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="text" name="Yourname">Your name<br>
<input type="submit" name="submit" value="Submit">
</form>
<?
}else{
// form has been submitted (the value of $submit is found)
session_start();
// add Yourname into the session
$_SESSION['usersname'] = $_POST['Yourname'];
// create a 'shortcut' to access the session
$usersname = $_SESSION['usersname'];
// show Yourname (now known as $usersname) on the page
echo $usersname;
// see example of session...
echo '<script>function nextpage(){ document.location="anypage.php";}setTimeout("nextpage()",4000);</script>';
?>
anypage.php
<?
//page to go to anytime after the form has been submitted
session_start();
echo $usersname;
?>
I think that's right, it's all done on the fly, so knowing my luck, it won't work
Nightfire
04-09-2003, 10:10 PM
And here's a thread about sessions and cookies
http://codingforums.com/showthread.php?s=&threadid=17023