SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Setting $_SESSION into a $_COOKIE

    Hi, I want to set a $_SESSION with a cookie so that the session can last longer so I do not get undefined index notices in a short space of time. Is the code below correct or do I need to modify something?

    Code:
    $inTwoMonths = 60 * 60 * 24 * 60 + time();
            setcookie('id', 'ID', $inTwoMonths);
            
            
            //line 20-23
            if (isset($_POST['id'])) {
            
            $_SESSION['id'] = $_POST['id'];
            
            }
            
            //line 30
            <?php echo $_SESSION['id'] ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    A session should live until the browser is closed. If you are loosing your session variables during a session, maybe there's something wrong? Do you do session_start() at the top of each script?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes there is a session_start() in each script

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2011
    Location
    Portland
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use a cache system or a key value database such as redis with predis etc... there is many solutions to this problem.
    coming soon sitejuju.com my new development portfolio


Tags for this Thread

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
  •