SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2003
    Location
    Denmark
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using sessions to store informations across pages

    Anyone can show an example as how you use sessions to store information across pages? For instance for the following scenario:

    1) Loginform is shown (login.php)
    2) User punches in wrong credentials (login.php)
    3) Errormsg is shown with the form (login.php)
    4) User tries again - this time with the right credentials (login.php)
    5) Dashboard is shown with a msg saying that login was successful (dashboard.php)

    I guess you would wrap it in an object:

    PHP Code:
    // without proper error handling
    class Log_Session {
        function 
    __construct() {}
        function 
    log($type$msg) {
             
    $_SESSION[$type] = $msg;
        }
        function 
    getLog($type) {
            return 
    $_SESSION[$type];
        }

    Would that be how you would do it?

  2. #2
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you might want to try this question in the php OOP forum. You should take a look at http://au.php.net/session to get the basics.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2003
    Location
    Denmark
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I posted this question in the PHP Design forum, but it was moved here. I don't know why, because it is exactly a design question. Which design would you apply to a situation like this. I know how to store stuff in a session, so that is not the question.

  4. #4
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lsolesen View Post
    I guess you would wrap it in an object:
    No need of wrappers, it is already conveniently wrapped in $_SESSION, so just use:

    PHP Code:
    session_start(); //Put this on top of each page

    //Then get the informatio you want
    if(isset($_SESSION['member_name']&&$_SESSION['member_name']!=""){
        
    $member_name $_SESSION['member_name'];
    }else{
        
    $member_name "";


  5. #5
    SitePoint Zealot
    Join Date
    Oct 2003
    Location
    Denmark
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I get a post moved back to where I posted it, and where it belongs?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •