Wednesday, 07 January 2009
   
Home arrow Tutorial  
 
Home
Supporto
Contattaci
Categorie Script
RSS Media Grabber Video & Foto Divertenti Storie di Vita (Flash) Video: Ricerca & Download Script Download Video Nazioni in Vendita Script per Sondaggi Host per File wap Script Creazione SlideShow Script PhotoCube Script "Make Confessions" Script Spartiti Chitarra Crea Smile Personalizzati URL Brevi & Sottodomini Script Gioco Hot Or Not Metti il Tuo Testo Sulle Img Host & Watermark Img Salva i Tuoi Preferiti Online Componenti Joomla Script a Basso Costo
Partners
StileGames
Php Tutorial
 
 
   
 
A Simple Sessions Tutorial Print E-mail

To begin with, we need to look at the various functions that we will be using and explain them a bit. First, session_start(). This one is probably the most important one of the group. This function is required on every page (unless you change a setting in the php.ini file) so that you can safely pass the session ID to it and it will know what to do with it. Generally, I put it by itself, up before the header information is sent.  <? session_start( ); ?>

This allows the page to take in all of the session information, including registered variables. This is the next thing that we come to. Now, sessions and all are well and good, but what's the real use in them? Why get them up and integrated into your website unless you can make them bow to your almighty programmer's will? Well, fear no more! The next function is your Holy Grail. The session_register() function provides you with the means to pass variables "imbedded" within the session. This makes for greater ease in continuing a users login over the course of several pages. I have found it easier to put this statement up at the top of the page also. Usually, it's only needed on the page that you are putting in the initial value for a variable on. For instance, going back to our login form example, on that page you would probably want something like: 

<?
session_start();
session_register("username","password");
?>

This would imbed the values of the variable $username and $password in the session. Also note that you use the names of the variables, and not the actual variable name. It won't work if you try putting in the actual variable names. That's all there is to it! Now that we have the variables in there mix and the session information ready to go, how do we get it to another page? Easy, trust me. To get it all over there, we just need to pass the session ID to the next page, and as long as it starts off with a 

<?
session_start();
?>



then it will be able to access the registered variables inside. The issue arises though, how do I go about passing the session ID to the next page? Easy. 

<?
$session=session_id();
?>
<a xhref="next.php?<?echo $session?>">next</a>



See? Told you it was easy! Just use the session_id() function to get the current session's ID information. Now, last but not least, what happens when we want to get rid of the session and destroy all of the data associated with it? Well, look no further! The session_destroy() function is all you need. All you do is call it (with no variables or anything passed to it) and it will get rid of the current session. Great for a "log-off" button. So, anyway, that's our brief overview for sessions and some of the issues involved with them. I know that there are several things that I didn't cover, but this is just a quick sketch of sessions and how to use them in a simple situation.

 Credit: phpdeveloper.org





Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
 
< Prev   Next >
 
Se trovi uno dei nostri operatori online, contattalo prima di comprare per usufruire di uno sconto!
Servizi
Controlla PageRank
Richiedi un Preventivo
Script Gratuiti
Installazione Script
Blog Backlinks
Login Form
Prodotti Scontati
Watermark and Host Images
Watermark and Host Images
$45.00
$35.00
You Save: $10.00
Add to Cart
 
Copyrighted © 2006 phppod.com