Results 1 to 9 of 9

Thread: php session

  1. #1
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy php session

    Hi all.

    I am new to this forum, and would like to know if anyone can help me with this problem...

    I am setting up a page for my friend so that it can only be accessed once, or may I say used once....

    On page 1 I have the following:

    PHP Code:

    <?php

    session_start
    ();
    // store session data
    $_SESSION['views']= "asdgh37rtcbgvsdfsrt";
    header("Location: page2.php?key=gadghas656asd2f");

    ?>
    And on page 2 I have this:

    PHP Code:

    <?php

    if($_SESSION['views'] =="asdgh37rtcbgvsdfsrt" $_GET['key'] =="gadghas656asd2f"){

    session_destroy();

    echo 
    "You passed!";

    }else{

    echo 
    "You have accessed this page already! Go Away!";

    }

    ?>
    However, when you visit page 1, it redirects normally but shows the words "You have accessed this page already! Go Away!", but it should really show "You passed!", and then when page two is accessed again, it should only show "You have accessed this page already! Go Away!" Since the session is distroyed. So what am I doing wrong here.

    // Note: //

    The user never knows about page 1....

    Can anyone help me!

    Many Many Thanks! - This forum rocks.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try adding the part in red to the following line:

    Code:
    if($_SESSION['views'] =="asdgh37rtcbgvsdfsrt" && $_GET['key'] =="gadghas656asd2f"){
    Hope this helps.

  3. #3
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I am sorry but it doesn't work..., I am using it to allow access to a flash game, would this make a difference?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That shouldn't have anything to do with it, but try adding session_start(); at the top of page2.php and see if that works.

    EDIT: have tested that, and it does work. If it doesn't work for you, then it may be with your server.
    Hope this helps.

  5. #5
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thankyou. It did work OK now with the session_start at the top of page 2.

    How long have you been with this forum?

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    If you look at my profile (or even the short stats on my posts) you will see that I have been a part since September of 2006. Anyways, glad to hear it is working for you now, and let me know if you need any more help.

  7. #7
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes... just one more question:

    How many characters are allowed to be in a URL. I want to make my keys as long and as obscure as possible..

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I believe it's 255 charatcers that can be passed in the URL, but not sure if that includes that rest of the address (http://www.whatever.com/blah) or if it is just any information in using the GET method. I will do some research on it, and let you know if it is different.

    Added later: according to w3schools, it is a max of 100 characters. See their site here:

    http://www.w3schools.com/php/php_get.asp

  9. #9
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thankyou again. Have a good day.
    Last edited by php-5; 02-28-2007 at 04:56 AM.

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
  •