Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Session cookies

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England
    Posts
    172
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session cookies

    How do you create session cookies using PHP ?

    And will it work if the person's browser blocks normal cookies ?

    Rich.
    \o/

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    All the info you need on sessions (about mid-way down are examples)

    http://www.php.net/manual/en/ref.session.php

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England
    Posts
    172
    Thanks
    0
    Thanked 0 Times in 0 Posts


    I'm not good at these things. Testing at the moment. It did set it once, but on main.php is still said it wasn't set. Then I unset it and set it again, and it didn't set.

    main.php:

    PHP Code:
    <?php
    if (isset($_SESSION['count'])) { echo "Session on."; };
    if (!isset(
    $_SESSION['count'])) { echo "Session off."; };
    ?>
    <br>
    <a href="reg.php">Set cookie.</a><br>
    <a href="unreg.php">Unset cookie.</a>
    reg.php:

    PHP Code:
    <?php
    session_start
    ();
    if (!isset(
    $_SESSION['count'])) {
        
    $_SESSION['count'] = 0;
    } else {
        
    $_SESSION['count']++;
    }
    ?>
    <a href="main.php">Session set. Click here for main area</a>
    unreg.php:

    PHP Code:
    <?php
    session_start
    ();
    // Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
    unset($_SESSION['count']);
    ?>
    <a href="main.php">Session unset. Click here for main area</a>
    \o/

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    looks like you forgot to add session_start() on main.php

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    England
    Posts
    172
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks
    \o/


  •  

    Posting Permissions

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