Forum Moderators: coopster

Message Too Old, No Replies

Problems with Sessions

         

Saboi

1:08 pm on Sep 23, 2007 (gmt 0)

10+ Year Member



Hi guys,

Hvaing problems with sessions. Need some advise.

Have a site with a loggin section. Have created the script below for loggin.

<?php

$username=$_POST["username"];

$password=$_POST["password"];

if((empty($username)¦¦empty($password))){header("Location:http:aaaaa.php");}

elseif($username=="ppppp" AND $password=="kkkkk"){ session_start(); $_SESSION['vincent'] = "Mr Man"; header("Location:success_one.php");}

elseif($password=="ddddddd"){ session_start(); $_SESSION['student'] = "Student"; header("Location:success_two.php");}

else{header("Location:dont_know you.php");}

?>

On each page i desire protected i have the following

<?php

session_start();

$compare = $_SESSION['vincent'];

$name = "vincent";

if( "$compare"!= "$name"){ header("Location:please_login.php");}

?>

Problems is even when both password and username are correct as predefined, the browswer takes me straight to the please_loggin page.

Can someone please advise where i am going wrong.

Thanks.

Saboi

cameraman

5:11 pm on Sep 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On your protected pages you're checking to see if the value of the session variable is 'vincent', but on your login page you set the value equal to 'Mr Man'.

'Mr Man' is never going to equal 'vincent', so you're always going to get sent to the please_login.php page.

If the password is those several d's, you're not setting the $_SESSION['vincent'] variable at all, you're instead setting $_SESSION['student'], so it looks like you need to check both session variables, unless success_two is the start of an entirely different road that doesn't have the same code segment you posted for the second part.

Saboi

7:42 am on Sep 26, 2007 (gmt 0)

10+ Year Member



Hi,

Thanks for the observation. I have made changes and getting the following errors

Warning: main() [function.main]: HTTP request failed! HTTP/1.1 404 Not Found in /home/marketin/public_html/folder/pasomba.php on line 3

Warning: main(http://www.example.com/check_cookie.php) [function.main]: failed to open stream: Success in /home/example/public_html/folder/pasomba.php on line 3

Warning: main() [function.main]: HTTP request failed! HTTP/1.1 404 Not Found in /home/example/public_html/folder/pasomba.php on line 3

Warning: main(http://www.example.com/check_cookie.php) [function.main]: failed to open stream: Success in /home/marketin/public_html/folder/pasomba.php on line 3

Warning: main() [function.include]: Failed opening 'http://www.example.com/check_cookie.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/example/public_html/folder/pasomba.php on line 3

Where could i be going wrong. I have double checked and the files are in there respective folders.

Please advice.

[edited by: dreamcatcher at 10:25 am (utc) on Oct. 3, 2007]
[edit reason] Use example.com, thanks. [/edit]

Saboi

9:33 am on Sep 26, 2007 (gmt 0)

10+ Year Member



Guys,

I figured out the problem and have it worked out. I had nt saved one file in my folder. However, the previous problem persists.

It keeps on taking me to page ssss.php even when both the password and username are correct. The loggin code is

<?php

session_start();

$username=$_POST["username"];

$password=$_POST["password"];

if((empty($username)¦¦empty($password))){header("Location:input_error.php");}

elseif($username=="pppp" AND $password=="tttt"){ $_SESSION['student'] = "President"; header("Location:enter.php");}

elseif($password=="mmmm"){ $_SESSION['general_student'] = "Student"; header("Location:general.php");}

else{header("Location:do_not_know.php");}

?>

On each page i want protected i have

session_start();

$name = $_SESSION['student'] ;

if( $name!= "President")

{

header("Location:student_section.php");

}

?>

Problems is that it keeps on taking me to student_section.php.

Please advice, where am i going wrong?

Habtom

10:01 am on Sep 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Though I wouldn't exactly write it that way, I couldn't spot any syntax or logic errors there.

My guess then falls on this part:

$username=$_POST["username"];
$password=$_POST["password"];

From where the form is submitted, do you have the input boxes named as username, and password. Is it on get or post?

Check the names to be correct. If you are not sure about the get or post, use the following:

$username=$_REQUEST['username'];
$password=$_REQUEST['password'];

Habtom

Saboi

10:25 am on Sep 26, 2007 (gmt 0)

10+ Year Member



Hi,

Yes i do have them from mu input page.

That part is just working fine. I think it has to do with the code below. It is not giving me errors but is just keeps taking me to the student_sction page, even though both username and password are correct.

<?php

session_start();

if($_SESSION['student']!== "Aaaaaa")

{

header("Location:student_section.php");

}

?>

The $_SESSION['student'] is set at loggin with the value Aaaaa.

What do you think?

Habtom

10:53 am on Sep 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php

session_start();

if($_SESSION['student']!== "Aaaaaa")

{

header("Location:student_section.php");

}

?>

That simply means either $_SESSION['student'] is not carrying any or the right value, or your "Aaaaaa" is not really "Aaaaaa".

Print it and see if it is carrying a value.

session_start();

if($_SESSION['student']!== "Aaaaaa")

{
echo $_SESSION['student'];
//header("Location:student_section.php"); (commented)

}

?>

d40sithui

11:21 am on Sep 26, 2007 (gmt 0)

10+ Year Member



why do you have!== to compare the strings. shouldn't it be!=

Saboi

12:14 pm on Sep 27, 2007 (gmt 0)

10+ Year Member



Hi,

Yes it did print. The interesting thing is that on my computer it works fine but once uploaded it does not and give the undesired result.

What do you think?

Saboi

8:17 am on Oct 3, 2007 (gmt 0)

10+ Year Member



Hi,

I think i am losing the variable in the global $_[]; upon redirecting to another url.

I am still searching how best to go round this. If you know of a way, please fill me in.

Thanks!

Saboi

8:24 am on Oct 3, 2007 (gmt 0)

10+ Year Member



I meant $_SESSION['blablabla'];

Saboi

10:09 am on Oct 3, 2007 (gmt 0)

10+ Year Member



Guys,

I am literally losing the content of my $_SESSION['#*$!X'] uon redirecting. As a result when checking is it is set on the next pages i am redirected back to the loggin page. I try to keep the session like this

if($pass = "#*$!x"){session_start(); $_SESSION['name'] = "yyyy";session_write_close(); header("Location:http://www.example.com"?.SID);exit();}

else{header("Location:http://www.example2.com";}

On page two i have the following...

<?php

session_start();

if($_SESSION['name']!== "yyyy"){header("Location:http//www.example.com/dont_know_you.php";}

?>

It keeps on taking me to the dont_know_you.php page even when if($_SESSION['name'] is the same as yyyy.

I think the reason is because i have lost the variable global as it is printing null when i wanted to check its contents.

Advice please!

[edited by: dreamcatcher at 10:24 am (utc) on Oct. 3, 2007]
[edit reason] Use example.com, thanks. [/edit]

omoutop

11:27 am on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if($pass == "#*$!x")

header("Location:http://www.example.com?".SID);

check the above
print everything on screen to test if they are valid.
assign the new url into a variable and print it to test it is correctly

put session_start() at top of page before any code outside the if() statement

Saboi

2:23 pm on Oct 7, 2007 (gmt 0)

10+ Year Member



Guys,

Thanks for that observation. I made the necessary change and guess what, sessions are still not being displayed on subsequent pages. I think that they are still not being past. What do you think? Below is my code

//Loggin pagin page

<?php

$username=$_POST["username"];

$password=$_POST["password"];

if((empty($username)¦¦empty($password))){header("Location:http://www.example.com/input_error.php");}

elseif($username=="#*$!" AND $password=="ppp"){ session_start(); $_SESSION["#*$!] = "Name"; session_write_close(); header("Location:http://www.example.com/example/example.php?".SID);}

elseif($password=="vvv"){ session_start(); $_SESSION["student"] = "Student"; session_write_close(); header("Location:http://www.example.com/enter.php?".SID);}

else{header("Location:http://www.example.com/do_not_know.php");}

?>

Ehen the password and the username are both correct, i am redirected to example.com/example/example.php where i have "included" the following

<?php

session_start();

if( $_SESSION["#*$!"]!== "Name")

{

header("Location:http://www.example.com/go_away.php");
exit();

}

?>

Unfortunately i am being sent away! Where do you think i am going wrong now.

Please advice.

Saboi