SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Glasgow
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session & Cookies

    Hello,

    I am looking for some help, at the moment I am *just* learning php and I am working on changing our site a little.

    When a user logs into the system a session is created and stored in the database (custom session not php session). The problem I have is that every link on the website must be formatted like this....

    PHP Code:
     <a href="filename.php<?php echo ?usersession=$usersession ?> </a>
    If the link isn't sorted like that then the user is logged out. Right now I have managed to store $usersession in a cookie but my question is what would be the code I would need to be able to remove the session code after the filename.php and use cookies to store the session and use it on each page?

  2. #2
    SitePoint Addict psyon's Avatar
    Join Date
    May 2004
    Location
    Cedar Rapids
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP sessions should use cookies automatically if they are available, and if not, last I looked it automatically put the session ID on the end of all internal links.

    Are you not using PHPs built in sessions? If not, look into session_start() on php.net

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Glasgow
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by psyon
    PHP sessions should use cookies automatically if they are available, and if not, last I looked it automatically put the session ID on the end of all internal links.

    Are you not using PHPs built in sessions? If not, look into session_start() on php.net
    Hello,

    No these are custom sessions then placed in a DB so thats why I am trying to figure this out

    I already knoww who to store the session in a cookie I just don't know what code to place on other pages to use the cookie.

  4. #4
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from what you wrote this should help

    PHP Code:
    $usersession $_GET['usersession']; 


    "Will I ever find my way to GURU?"

  5. #5
    SitePoint Zealot ChrisOSX's Avatar
    Join Date
    May 2002
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your sessions are important to the site as they sound like they are, and you are storing them in cookies, I hope you are encoding the session ID before you are writing it to the cookie...

    Depending on what else you are storing in your cookie you might need something like this:

    PHP Code:
    if( issset$_COOKIE[$name] ) )
    {
      
    $cookievars $_COOKIE[$name];
      if( 
    $_GET['usersession'] == $cookievars['usersession'] )
      {
        
    // We are in the clear, do your thing...
       
    }
       else
       {
        
    // They don't match, don't do your thing...
       
    }



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
  •