Jump to content

[SOLVED] session / php issues


wmguk

Recommended Posts

Hi guys,

 

I've got a login script, basically when you log in to the site it sets a session.

 

this is the code:

 

<?php
//Engage sesions.
session_start();
// Here we include the mysql connection script.
include("connection.php");

$email=$_POST['email']; 
$password=$_POST['password']; 

/* Select data from database. */
$sql="SELECT * FROM users WHERE email='$email' and password='$password'"; 
$result=mysql_query($sql); 
$count=mysql_num_rows($result);
$row = mysql_fetch_assoc($result);
$coname = $row['coname'];

/* If only one occurrence is there. */
if($count==1){
/* Set the myusername sesion to 1 */
$_SESSION['email'] = $email;
$_SESSION['password'] = $password; 
if ($coname==''){
$_SESSION['create'] == 'true';
} else {
$_SESSION['create'] == '0';
}
/* Make an sesion called authenticated to tell main.php that the user is logged in. */
$_SESSION['authenticated'] == 'true';
header("location:../main.php");
exit;
} 
else 
{ 
header("location:../failed.html");
exit;
} 
?>

 

what I want to do is

<? if ($coname = "") {

$_SESSION['create'] == 'true' ;

} else {

$_SESSION['create'] == 'false' ;

}

 

then on my pages I can pull out $create = $_SESSION['create'] ;

 

however it doesnt appear to be working...

 

i get

 

Notice: Undefined index: create in /var/www/vhosts/wicked-websites.co.uk/subdomains/bni/httpdocs/admin/main.php on line 7

 

so its not setting $create

 

any thoughts?

Link to comment
https://forums.phpfreaks.com/topic/122753-solved-session-php-issues/
Share on other sites

I think your code may be authenticating the user even if the count was 0. You have the line "$_SESSION['authenticated'] == 'true';" outside of the if statement concerning the count. Perhaps the session variables aren't getting set. Perhaps you should throw a javascript alert up before the redirect just to be sure the session variables are getting set.

 

<script type="javascript">
alert(<?php echo "\$_SESSION['create'] = $_SESSION['create']" ?>);
</script>

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.