Jump to content


Photo

Sessions dont work


  • Please log in to reply
10 replies to this topic

#1 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 04:12 PM

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:

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";
    }
}

And here is the code that checks if there is someone logged in:

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'];
} }
}

Can anyone please help me :'(

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 27 February 2006 - 04:16 PM

each page MUST start with

session_start();

the login page and every page you use after. This should be the first line in your script.

Ray

#3 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 04:18 PM

[!--quoteo(post=349856:date=Feb 27 2006, 05:16 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:16 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
each page MUST start with

session_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.

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 27 February 2006 - 04:30 PM

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

#5 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 04:32 PM

[!--quoteo(post=349864:date=Feb 27 2006, 05:30 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:30 PM) View Post[/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.

#6 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 27 February 2006 - 04:39 PM

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

#7 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 04:42 PM

[!--quoteo(post=349872:date=Feb 27 2006, 05:39 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:39 PM) View Post[/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.

#8 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 27 February 2006 - 04:55 PM

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

#9 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 05:10 PM

[!--quoteo(post=349882:date=Feb 27 2006, 05:55 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Feb 27 2006, 05:55 PM) View Post[/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.

#10 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 06:46 PM

No ideas?

#11 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 28 February 2006 - 09:10 AM

[!--quoteo(post=349924:date=Feb 27 2006, 07:46 PM:name=Ge64)--][div class=\'quotetop\']QUOTE(Ge64 @ Feb 27 2006, 07:46 PM) View Post[/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]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users