sessions

  • seularts
  • Graduate
  • Graduate
  • User avatar
  • Posts: 153
  • Loc: Romania

Post 3+ Months Ago

Can i make a session within a php file with no database interferance!?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

yes ... you can ...
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

ummm...r_t? care to expound?
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

sure, well "making a session" wouldn't be completely the correct term ... maybe "setting a session variable" would be a better description ...

Setting a PHP session variable consists of two steps ... firstly, you need to tell PHP that you are going to use session variables on the page you are on ... with the following:
Code: [ Select ]
<?php
session_start();
?>
  1. <?php
  2. session_start();
  3. ?>

then you need to choose a name for your session variable and maybe assign a value to it aswell, like the following:
Code: [ Select ]
<?php
$_SESSION['r_t'] = "Awesome!";
?>
  1. <?php
  2. $_SESSION['r_t'] = "Awesome!";
  3. ?>

So in the example above, my session variable's name is "r_t" and the value of that variable is "Awesome!"

Now you can use this session variable on other pages too, maybe something like this:
Code: [ Select ]
<?php
session_start();
echo "the word I set the session variable to on the previous page is: " . $_SESSION['r_t'];
?>
  1. <?php
  2. session_start();
  3. echo "the word I set the session variable to on the previous page is: " . $_SESSION['r_t'];
  4. ?>


Now please note that once the user closes down the browser/tab that your site was in, it takes a few minutes and then that session variable does not exist anymore ... and it also expires after about 20 minutes of inactivity on a site ...

//never knew the word expound, and thanks to "ubiquity" I just highlighted it, pressed CTRL+SPACE and typed def and enter and it gave me an explanation of what it means ... cool ...
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

I actually expected you to bring up cookies
http://www.hudzilla.org/phpbook/read.php/10_0_0
Session cookies are the way to do it without database interference.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

Sessions in php, by default, use cookies. If cookies aren't turned on in the browser, it tacks the php session id onto the URL. There is no requirement whatsoever to use a database connection with sessions. It definitely makes the session more useful to store bits in a database, but there's no requirement.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 104 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.