MySQL
  Home arrow MySQL arrow Page 4 - Developing Custom PHP Sessions
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Developing Custom PHP Sessions
By: Brian Rosner
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 21
    2002-07-21

    Table of Contents:
  • Developing Custom PHP Sessions
  • Developing the Backend
  • Creating the Session Functions (contd.)
  • Using Our Sessions
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing Custom PHP Sessions - Using Our Sessions


    (Page 4 of 5 )

    Let's start by creating a new file named login.php. Add the following code to login.php:

    <?php

    include "sess.php";

    if($login) {

    $sess = new session;

    $sess->start();

    $sess->register($username);

    header("Location: welcome.php");

    }

    ?>
    <html>
    <head>
    <title>login</title>
    </head>

    <body>

    <form method="post" action="<?= $PHP_SELF; ?>">

    Username: <input type="text" name="username"><br>
    Password: <input type="password" name="password"><br>
    <br>
    <input type="submit" name="login" value="Login">

    </body>
    </html>


    The code above has our login form and if it's submitted it will initialize the class and use the proper functions to start and register the values. Then the user is redirected to the welcome.php page.

    Last, but surly not least, we need to create our welcome.php page:

    <?php

    include "sess.php";

    $sess = new session;

    if($logout == "yes") {
    $sess->destroy();
    header(“Location: login.php”);
    exit;
    }

    $sess->read();
    ?>
    <html>
    <head>
    <title>welcome</title>
    </head>

    <body>

    Welcome, <?= $sess_val; ?><br>
    <a href="<?= $PHP_SELF; ?>?logout=yes">Logout</a>

    </body>
    </html>


    Since this page is the first one to use our sessions with the passing key, we call the read() function to fetch the value. As seen in the read() function, we saved the value to $sess_val so where we want that data to appear we print it to the user. Then we offer a link to log out, which uses the destroy() function to kill the current session.

    More MySQL Articles
    More By Brian Rosner


     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT