Jump to content

$_SESSION[] & setcookie() problem


tecmeister

Recommended Posts

Ok.  I thought there might be a problem with the server.

 

This is the code for where I'm trying to set the session and cookie.

 

<?php
session_start();
if((isset($_GET['signin'])) && ($_GET['signin'] == "check")){
require_once("include/class.php");
$database->dbConnect();
//------------Collect $_POST---------\\
$user = $_POST['user'];
$pass = $_POST['pass'];
//----------------Connect to Personal Database--------------------------\\
$sql = "SELECT user,pass,active FROM personal WHERE user='$user' AND pass='$pass'";
$result = $database->query($sql);
$row = $database->fetchAssoc($result);
//-----------------------Not Activated---------------------------\\
if($row['active'] != 1){
	header("location: http://aerialfusion.co.uk/index.php?signin=notActivated");	
}
//-----------------------SESSION Log In---------------------------\\
if(($row['active'] == 1) && (empty($_POST['stayIn']))){
	$_SESSION['user'] = $user;
	header("Location: http://members.aerialfusion.co.uk");
}
//-----------------------COOKIE Log In---------------------------\\
if(($row['active'] == 1) && ($_POST['stayIn'] == "on")){
	setcookie("user",$user,time()+)
}
}else{
header("location: http://www.aerialfusion.co.uk?signin=ERROR");	
}
?>

 

If you need other pages code then please tell me.

 

tecmeister.

Link to comment
Share on other sites

You are setting the session variable if $_POST['stayIn'] IS empty AND $row['active'] IS NOT 1, thats what its supposed to do? If so, then try debugging the variables and see if they actually have correct info as they should have when the session variable should be set. Make sure your condition evaluates to true when it should. You can also test if the script goes inside the if clause where you are supposed to set the session variable by simply adding a test echo inside the if.

Link to comment
Share on other sites

I have made the session so it is like this:

 

if($row['active'] == 1){
	$_SESSION['user'] = $user;
	header("Location: http://members.aerialfusion.co.uk");
}

 

I'm still getting the same problem.

I've also tried to do the same of every page just fro testing and it is having a problem setting the session and cookie.

 

Is there something wrong with the server etc.  Could someone please could you help me.

 

tecmeister.

Link to comment
Share on other sites

Sorry I don't really understand?

If you mean debug the server then no.  It is not my server.

Please would you be able to reword it.

 

I all started having this problem recently.  It all worked then the session stopped then the cookie stopped.

 

Thanks for your help,

 

tecmeister.

Link to comment
Share on other sites

Debug = finding the bugs and fixing them. Put echo 'TEST'; inside that IF, and see if that TEST will get printed, if not the script never goes inside the IF and that means also the session variable never gets set.

 

Or simply test if the sessions work in the beginning of your script.

 

<?php
session_start();
$_SESSION['test'] = 'TEST';
var_dump($_SESSION['test']);

 

See if that outputs anything?

Link to comment
Share on other sites

So that means atleast the sessions works for you, because in there you 1. start session, 2. set a session variable called test, 3. dump the contents of that variable.

 

edit: Could you post the whole code you are trying to run? Maybe there is something wicked. Including the parts where from you get all the $_GET variables and $row[''] variables.

Link to comment
Share on other sites

The cookie is working now but not the session.  If this helps I'm trying to set the session on a sub-domain signin.

 

This is all of the login page:

 

<?php
session_start();
	require_once("include/class.php");
	$database->dbConnect();
	$database->errorReport();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/main.css" rel="stylesheet" rev="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aerial Fusion | Parkour/Free Running </title>
</head>

<body>
<?php
if((isset($_SESSION['user'])) || (isset($_COOKIE['user']))){
?>
<div id="headerBar">
<div id="header">
    	<a href="http://aerialfusion.co.uk/index.php"><div id="headerLogo">
        	Aerial Fusion
        </div></a>
        <div id="headerInfo">
        	<?php if(isset($_SESSION['user'])){ ?>
        			<dt><a href="#"><?php echo $_SESSION['user'] ?></a></dt>
            <?php
                }else if(isset($_COOKIE['user'])){ ?>
                	<dt><a href="#"><?php echo $_COOKIE['user'] ?></a></dt>
            <?php
			}
		?>
            		<dt><a href="#">Friends</a></dt>
                    <dt><a href="#">Messages</a></dt>
                    <dt><a href="#">Settings</a></dt>
                    <dt><a href="logout.php">Logout</a></dt>
        </div>
     	<div id="headerSearch">
        	<form action="#" method="post">
            	<input type="text" name="search" />
            	<input type="submit" value="Search" />
            </form>
        </div>
    </div>
</div>
<?php
}
else{
?>
<div id="headerOutBar">
<div id="headerOut">
    	<a href="http://aerialfusion.co.uk/index.php"><div id="headerLogoOut">
        	Aerial Fusion
        </div></a>
        
        <table id="headerSignin">
        	<form action="http://signin.aerialfusion.co.uk/index.php?signin=check" method="post">
        	<tr>
            	<td>Stay Signed In <input type="checkbox" name="stayIn" /></td>
                <td>Forgotton your password?</td>
                <td>Register</td>
            </tr>
            <tr>
            	<td height="24"><input type="text" name="user" value="Username" onfocus="value=''" /></td>
                <td><input type="text" name="pass" value="Password" onfocus="type='password',value=''" /></td>
                <td><input type="submit" value="Sign In" /></td>
            </tr>
            </form>
        </table>
    </div>
</div>
<?php
}
if((isset($_SESSION['user'])) || (isset($_COOKIE['user']))){
?>
<div id="personal">
    <div id="personalImage">
    	<?php
		if(isset($_SESSION['user']))$user = $_SESSION['user'];
		if(isset($_COOKIE['user']))$user = $_COOKIE['user'];
		$sql = "SELECT imagePath FROM personalImageWhere user='$user'";
		$result = $database->query($sql);
		$row = $database->fetchAssoc($result);
		if(empty($row['imagePath'])){
		?>
            	<h2> No Image </h2>
                <form action="<?php $_SERVER['PHP_SELF']?>?personal=image&user=<?php $user ?>" enctype="multipart/form-data" method="post">
                  <input size="13" type="file" name="image" />
                  <br /><br />
                    <input type="submit" value="Add Personal Image" />
      </form>
      <?php	
		}
	?>
    </div>
    <div id="personalData">
    	<font color="#999">NAME: </font>
    	<?php
        	$sql = "SELECT * FROM personal WHERE user='$user'";
		$result = $database->query($sql);
		$row = $database->fetchAssoc($result);
		echo $row['name']." ".$row['last'];
	?>
    </div>
    <div id="personalData">
    	<font color="#999">AGE: </font>
    </div>
    <div id="personalData">
    	<font color="#999">COUNTY: </font>
    	<?php
		echo $row['county'];
	?>
    </div>
</div>
<?php
}
?>
</body>
</html>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.