wmguk Posted September 4, 2008 Share Posted September 4, 2008 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 More sharing options...
NathanBrisk Posted September 4, 2008 Share Posted September 4, 2008 Just to check--are you continuing your session on these subsequent pages? Is session_start(); on each following page you're trying to access these session variables on? Link to comment https://forums.phpfreaks.com/topic/122753-solved-session-php-issues/#findComment-633877 Share on other sites More sharing options...
wmguk Posted September 4, 2008 Author Share Posted September 4, 2008 yeah, i've got this on each page <?php session_start(); if (!isset($_SESSION['email'])) { header('Location: http://www.domain.co.uk/admin'); exit; } $email = $_SESSION['email']; $create = $_SESSION['create']; ?> Link to comment https://forums.phpfreaks.com/topic/122753-solved-session-php-issues/#findComment-633883 Share on other sites More sharing options...
revraz Posted September 4, 2008 Share Posted September 4, 2008 When you set a variable, you just need to use one = not two if ($coname==''){ $_SESSION['create'] = 'true'; <---------------------- } else { $_SESSION['create'] = '0'; <----------------------- } Link to comment https://forums.phpfreaks.com/topic/122753-solved-session-php-issues/#findComment-633885 Share on other sites More sharing options...
NathanBrisk Posted September 4, 2008 Share Posted September 4, 2008 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> Link to comment https://forums.phpfreaks.com/topic/122753-solved-session-php-issues/#findComment-633887 Share on other sites More sharing options...
wmguk Posted September 4, 2008 Author Share Posted September 4, 2008 Excellent, Thank you. This is now solved - the == problem! Link to comment https://forums.phpfreaks.com/topic/122753-solved-session-php-issues/#findComment-633929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.