Jump to content


- - - - -

[PHP] - [Sessions] - [ltjfansite]


  • Please log in to reply
2 replies to this topic

#1 _*ltjfansite_*

_*ltjfansite_*
  • Guests

Posted 05 September 2004 - 11:20 AM

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 :P

#2 iPixel

iPixel

    Young Padawan

  • Members
  • Pip
  • 19 posts

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 adam123

adam123

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 2,306 posts
  • Location:London, UK
  • Interests:Programming and stuff.

Posted 04 June 2005 - 12:53 PM

How do you keep a session alive ... because right now by closing a browser your sessions gets automatically destroyed.

That's how sessions work, if you want them to last, use cookies instead.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users