This Tut Was Writen By Freendom Of Zanmato Design and i had permision to post this tut.
You can find the ut on this page here
Click here
-------------------------------------
Here is a simple session tutorial. First, sessions are things stored on the server, therefor, the person cannot see them unless you print it. Here are how you use this.
First offYou must put session_start(); at the beginning of every page that you will use sessions in! (Make sure it is inside the php tags)
To make a sessionYou use this syntax:
<?php
$_SESSION['session_name'] = "SESSION CONTENT";
?>
NOTE: Sessions must be made at the VERY top of a file, before ANYTHING is sent to the viewers browser, OR it will NOT work... but you can access them at any time.
To access a sessionAccessing a session is easy. Just like this...
<?php
echo "The content of a session is $_SESSION['session_name']";
?>
So, if the content of the session 'session_name' was CONTENT, on the screen you would see:
The content of a session is COTNENT
NOTE: If you are using echo ''; and not echo ""; you will need to put { and } around the session when printing it, example:
<?php
echo 'The content of a session is {$_SESSION['session_name']}';
?>
To delete a session and the cookie where the session ID is storedThe session ID is something to identify the current session, it doesn't store any of the actual sessions content. So, to delete all sessions by that person, you need to use this:
<?php
session_destroy();
$_SESSION = array();
setcookie ('PHPSESSID', '', time-300, '/', '', 0);
?>
That's about all! Ask if I forgot something
[PHP] - [Sessions] - [ltjfansite]
Started by
_*ltjfansite_*
, Sep 05 2004 11:20 AM
2 replies to this topic
#1 _*ltjfansite_*
Posted 05 September 2004 - 11:20 AM
#2
Posted 02 June 2005 - 03:31 PM
How do you keep a session alive ... because right now by closing a browser your sessions gets automatically destroyed.
#3
Posted 04 June 2005 - 12:53 PM
That's how sessions work, if you want them to last, use cookies instead.How do you keep a session alive ... because right now by closing a browser your sessions gets automatically destroyed.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users