Forum Moderators: coopster
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
'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.
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]
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?
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
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?
<?phpsession_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)
}
?>
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]
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