tecmeister Posted September 9, 2009 Share Posted September 9, 2009 Hi guys, Now for some reason I can not set a $_SESSION[] or setcookie(). Does anyone have an idea of why this is happening? Thanks for your help, tecmeister. Link to comment https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/ Share on other sites More sharing options...
shergold Posted September 9, 2009 Share Posted September 9, 2009 umm.... how do you expect someone to be able to tell you a solution to the problem if we cannot see your code? please post it. shergold. Link to comment https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915375 Share on other sites More sharing options...
tecmeister Posted September 9, 2009 Author Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915524 Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915537 Share on other sites More sharing options...
tecmeister Posted September 9, 2009 Author Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915542 Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 Did you debug if it ever goes inside that if clause? Link to comment https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915545 Share on other sites More sharing options...
tecmeister Posted September 9, 2009 Author Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915548 Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915551 Share on other sites More sharing options...
tecmeister Posted September 9, 2009 Author Share Posted September 9, 2009 It displays TEST. I have also put at the top of the code: error_reporting[E_ALL] and have tried error_reporting[-1]. Link to comment https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915557 Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 It should be <?php error_reporting(E_ALL); ini_set('display_errors', '1'); And did you try the code I posted one post ago and add that test session code to the very top of your script? Did it output anything? Any errors or anything? Link to comment https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915561 Share on other sites More sharing options...
tecmeister Posted September 9, 2009 Author Share Posted September 9, 2009 Yes and I got this: string(4) "TEST I also tried the code you have just given me and there was no errors. Link to comment https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915573 Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915574 Share on other sites More sharing options...
tecmeister Posted September 9, 2009 Author Share Posted September 9, 2009 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 https://forums.phpfreaks.com/topic/173650-_session-setcookie-problem/#findComment-915584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.