Log in

View Full Version : php session



php-5
02-28-2007, 02:28 AM
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

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

?>



And on page 2 I have this:




<?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!:confused: :confused:

Many Many Thanks! - This forum rocks.

thetestingsite
02-28-2007, 02:30 AM
Try adding the part in red to the following line:



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


Hope this helps.

php-5
02-28-2007, 02:36 AM
I am sorry but it doesn't work..., I am using it to allow access to a flash game, would this make a difference?

thetestingsite
02-28-2007, 02:48 AM
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.

php-5
02-28-2007, 03:03 AM
Thankyou. It did work OK now with the session_start at the top of page 2.

How long have you been with this forum?

thetestingsite
02-28-2007, 03:04 AM
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.

php-5
02-28-2007, 03:20 AM
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..

thetestingsite
02-28-2007, 03:24 AM
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

php-5
02-28-2007, 03:38 AM
Thankyou again. Have a good day.