Ge64 Posted February 27, 2006 Share Posted February 27, 2006 Hi all, Im working on a site and I am making it locally running on a server pc, and it works totally fine (PHP5). But when I upload it to my hosting server (PHP4.3) the sessions don't seem to work. I can log in but when I click a link its logged out again. I've checked and session.use_only_cookies is off here but on on the hosting side, but when I look in my cookies folder there is a cookie from my hosting with the session ID so that can't be the problem.The website is www.ge64.nl/alpha/ , you can log in with Lalala and bla. What it should do is show stats when you click Home Base but it doesnt, and it isnt a mysql problem because the top5 member thing does work. Here is the code for loging in:[code]if(!empty($_POST['login_name']) AND !empty($_POST['login_pass'])){ $login['name'] = $_POST['login_name']; $login['pass'] = md5($_POST['login_pass']); connectdb(); $query = "SELECT * FROM users WHERE `name` = '" . $login['name'] . "'"; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num < 1) { $loginattempt = "wrong user"; } mysql_close(); $i=0; while ($i < $num) { $name = mysql_result($result,$i,'name'); $pass = mysql_result($result,$i,'pass'); $i++; } if($pass == $login['pass']) { $_SESSION['name'] = $login['name']; $_SESSION['pass'] = $login['pass']; $loginattempt = "successful"; } else { $loginattempt = "wrong pass"; }}[/code]And here is the code that checks if there is someone logged in:[code]function islogin() {if(!isset($_SESSION['name']) OR !isset($_SESSION['pass'])) {return NULL;} else {global $sqlhost, $sqluser, $sqlpass, $sqldb;mysql_connect($sqlhost,$sqluser,$sqlpass);mysql_select_db($sqldb);$query = "SELECT * FROM users WHERE `name` = '" . $_SESSION['name'] . "'";$result = mysql_query($query);$num = mysql_num_rows($result);mysql_close();$i=0;while ($i < $num) {$name = mysql_result($result,$i,'name');$pass = mysql_result($result,$i,'pass');$i++; }if($pass == $_SESSION['pass']) {return $_SESSION['name'];} }}[/code]Can anyone please help me :'( Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/ Share on other sites More sharing options...
craygo Posted February 27, 2006 Share Posted February 27, 2006 each page MUST start withsession_start();the login page and every page you use after. This should be the first line in your script.Ray Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12744 Share on other sites More sharing options...
Ge64 Posted February 27, 2006 Author Share Posted February 27, 2006 [!--quoteo(post=349856:date=Feb 27 2006, 05:16 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:16 PM) [snapback]349856[/snapback][/div][div class=\'quotemain\'][!--quotec--]each page MUST start withsession_start();the login page and every page you use after. This should be the first line in your script.Ray[/quote]Sorry I forgot to mention it, but session_start(); is the first line on index.php and every other page goes through it so that isn't the problem. Also it does work at home so that can't be a problem. Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12745 Share on other sites More sharing options...
craygo Posted February 27, 2006 Share Posted February 27, 2006 setting for sessions are in the php.ini file. you might have to check with your hosting company and see if they are setup correctly. Usually you do not have access to this file so will have to contact the hosting company.If you have access you can post here and I will help best I can.Ray Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12750 Share on other sites More sharing options...
Ge64 Posted February 27, 2006 Author Share Posted February 27, 2006 [!--quoteo(post=349864:date=Feb 27 2006, 05:30 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:30 PM) [snapback]349864[/snapback][/div][div class=\'quotemain\'][!--quotec--]setting for sessions are in the php.ini file. you might have to check with your hosting company and see if they are setup correctly. Usually you do not have access to this file so will have to contact the hosting company.If you have access you can post here and I will help best I can.Ray[/quote]I checked with phpinfo(); and the only difference between my server and the hosting company's is that session.use_only_cookies is on there and off here. Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12752 Share on other sites More sharing options...
craygo Posted February 27, 2006 Share Posted February 27, 2006 Do you have cookies active on your PC? Your web setting might be stopping not the web server. Your sessions are being stored as cookies so your web setting might be the problem not the web server. If you want me to try and there is not any problem with it, give me the link and I will try it out.Ray Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12756 Share on other sites More sharing options...
Ge64 Posted February 27, 2006 Author Share Posted February 27, 2006 [!--quoteo(post=349872:date=Feb 27 2006, 05:39 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:39 PM) [snapback]349872[/snapback][/div][div class=\'quotemain\'][!--quotec--]Do you have cookies active on your PC? Your web setting might be stopping not the web server. Your sessions are being stored as cookies so your web setting might be the problem not the web server. If you want me to try and there is not any problem with it, give me the link and I will try it out.Ray[/quote]I checked and the cookie settings seemed ok, and there was also a cookie with the PHPSESSID from my site. You can try if you want, the site is [a href=\"http://www.ge64.nl/alpha\" target=\"_blank\"]http://www.ge64.nl/alpha[/a] and you can login with Lalala and password bla. Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12758 Share on other sites More sharing options...
craygo Posted February 27, 2006 Share Posted February 27, 2006 I logged in and when I click member list, I get a quick white page with php error but then it goes right into the page and it is all messed up. You should add "die();" in there so that the script ends when errors occur, just until you can debug. Looks like there are some errors in there but it passes by so quick I can't see them.Ray Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12763 Share on other sites More sharing options...
Ge64 Posted February 27, 2006 Author Share Posted February 27, 2006 [!--quoteo(post=349882:date=Feb 27 2006, 05:55 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:55 PM) [snapback]349882[/snapback][/div][div class=\'quotemain\'][!--quotec--]I logged in and when I click member list, I get a quick white page with php error but then it goes right into the page and it is all messed up. You should add "die();" in there so that the script ends when errors occur, just until you can debug. Looks like there are some errors in there but it passes by so quick I can't see them.Ray[/quote]Well that's because its not finished yet, the only pages that work are News, Home Base, and Plant. The other ones mess up the template because if there is no page it misses a table, and the errors are probably about the include file not existing. Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12767 Share on other sites More sharing options...
Ge64 Posted February 27, 2006 Author Share Posted February 27, 2006 No ideas? Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12797 Share on other sites More sharing options...
Ge64 Posted February 28, 2006 Author Share Posted February 28, 2006 [!--quoteo(post=349924:date=Feb 27 2006, 07:46 PM:name=Ge64)--][div class=\'quotetop\']QUOTE(Ge64 @ Feb 27 2006, 07:46 PM) [snapback]349924[/snapback][/div][div class=\'quotemain\'][!--quotec--]No ideas?[/quote]I fixed a few things but it still doesn't all work, I uploaded the new source code to [a href=\"http://ge64.nl/files/src.zip\" target=\"_blank\"]http://ge64.nl/files/src.zip[/a] Quote Link to comment https://forums.phpfreaks.com/topic/3680-sessions-dont-work/#findComment-12970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.