Jump to content

[SOLVED] sessions not registering as should


cooldude832

Recommended Posts

I am trying to make a login without mysql and it looks like

<?php 
session_start();
$username = "Admin";
$password = "user";
if($_POST['login'] == "yes"){
$user = $_POST['username'];
$pass = $_POST['password'];
if($user == $username && $pass == $password){
	$_SESSSION['admin'] = "yes";
	header("location: admin.php");
	echo "<pre> Login Valid</pre>";
}	
else{
	echo "<pre>Invalid Login Information</pre><br/>";
	die(include("login.html"));
}
}
if($_SESSION["admin"] != "yes"){
echo "Session: ".$_SESSION["admin"]."<br/>";
die(include("login.html"));
}
else{
echo "logged in";
}
?>

It test the username perfectly except it doesn't display the session right after logging in as it should it just says Session: and the login part

I have tried Double/single quotes on the session no difference, kinda getting annoying

heres where you initialize your session right?

if($user == $username && $pass == $password){

$_SESSSION['admin'] = "yes";

header("location: admin.php");

echo "<pre> Login Valid</pre>";

}

 

now i believe that condition is not satisfied so no initialization took place why?

 

if that is correct the you should get the error saying header cannot send somtething because you echo something under the header

weird i think it actually worrk but because the header thing it doesnt show the message

try to remove the header file or comment it first

in this code

if($user == $username && $pass == $password){

      $_SESSSION['admin'] = "yes";

      header("location: admin.php");-<<<<<<<<<<comment this first

      echo "

yeah, teng84 no good

<?php 
session_start();
$username = "Admin";
$password = "user";
if($_POST['login'] == "yes"){
$user = $_POST['username'];
$pass = $_POST['password'];
if($user == $username && $pass == $password){
	$_SESSSION['admin'] = "yes";
	//header("location: admin.php");
	echo "<pre>match</pre>";
}	
else{
	echo "<pre>Invalid Login Information</pre><br/>";
	die(include("login.html"));
}
}
if($_SESSION['admin'] != "yes"){
echo "Session: ".$_SESSION['admin']."<br/>";
die(include("login.html"));
}
else{
echo "logged in";
}
?>

technically its not an error (unless you are using strict) because you could have a superglobal array called SESSSION (three Ss) which all ti was doing was registering a static value instead of the session value.  I would need an editior that would pick up on predefined superglobals, which notepad++ doesnot

dreamweaver is not a text editor which is what you really need to build code in.  Dreamweaver is for the novice person who can't build layouts by hand so they use the GUI's in dreamweaver to build code.  You can find text editors with ftps built into them for your needs if that is what you use it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.