Member Panel


Sponsors and Ads

Live Tag Cloud

PC Forum PC Help Forum » Web & Networking » Web Design » [PHP] Sessions not working

Web Design - [PHP] Sessions not working posted in the Web & Networking forums; 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 ...

JOIN US NOW to remove these Ads

pc help forum number one in the search engines
Post New Thread  Reply
  #1  
Old 02-27-2006
Ge64's Avatar
P C H F R 0 0 l Z
 
Join Date: Oct 2005
Location: Hong Kong
Posts: 232
PC Experience: Good at least
Ge64 - See this Members User comments on their Profile page
Send a message via MSN to Ge64
Default [PHP] Sessions not working

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";
    }
}
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'];
} }
}
Can anyone please help me


__________________
PCHF RoX ur SoX
:computer1
PC SmAsH0R
  #2  
Old 02-27-2006
ladygreenwitch's Avatar
Elite Member
 
Join Date: Jul 2005
Location: Bay Area California
Posts: 4,642
ladygreenwitch - See this Members User comments on their Profile page ladygreenwitch - See this Members User comments on their Profile page ladygreenwitch - See this Members User comments on their Profile page
Default

:grin: Hey Ge,

Nice to see you back. The guys who code and know the ins and outs of websites are offline right now. I am sure that they will be around later today.

Be patient, I am sure they will have some ideas for you.

TTFN

LGW


  #3  
Old 02-27-2006
Spaceman3750's Avatar
Elite Member
My PC
 
Join Date: Jan 2004
Location: Riverton, IL, USA
Posts: 1,511
PC Experience: Very Experienced
Spaceman3750 - See this Members User comments on their Profile page
Send a message via AIM to Spaceman3750 Send a message via MSN to Spaceman3750 Send a message via Yahoo to Spaceman3750
Default

Hey there Ge64 .

You forgot to call session_start() before defining the session variables. I would recommend calling this at the beginning of the script, as it has to be called before anything is output to the browser.

-Ryan


__________________
- Ryan
http://www.spaceman3750.info
http://www.conglomerate-game.net

Cisco Academy - CCNA student
  #4  
Old 02-28-2006
Ge64's Avatar
P C H F R 0 0 l Z
 
Join Date: Oct 2005
Location: Hong Kong
Posts: 232
PC Experience: Good at least
Ge64 - See this Members User comments on their Profile page
Send a message via MSN to Ge64
Default

Hi,

I did call session_start(); at the top of index.php, and all other pages go through there. I uploaded the entire source to http://www.ge64.nl/files/src.zip

It does work on my PHP5 server but not on PHP4.3.


__________________
PCHF RoX ur SoX
:computer1
PC SmAsH0R
  #5  
Old 02-28-2006
Spaceman3750's Avatar
Elite Member
My PC
 
Join Date: Jan 2004
Location: Riverton, IL, USA
Posts: 1,511
PC Experience: Very Experienced
Spaceman3750 - See this Members User comments on their Profile page
Send a message via AIM to Spaceman3750 Send a message via MSN to Spaceman3750 Send a message via Yahoo to Spaceman3750
Default

PHP5 is not backward compatible with PHP4. The only thing in the entire two scripts that look remotely PHP5 is the AND operator, and that can easily be changed to && to make it PHP4 compatible (I think).


__________________
- Ryan
http://www.spaceman3750.info
http://www.conglomerate-game.net

Cisco Academy - CCNA student
  #6  
Old 02-28-2006
Ge64's Avatar
P C H F R 0 0 l Z
 
Join Date: Oct 2005
Location: Hong Kong
Posts: 232
PC Experience: Good at least
Ge64 - See this Members User comments on their Profile page
Send a message via MSN to Ge64
Default

Originally Posted by Spaceman3750
PHP5 is not backward compatible with PHP4. The only thing in the entire two scripts that look remotely PHP5 is the AND operator, and that can easily be changed to && to make it PHP4 compatible (I think).
I changed it, but it makes no difference. According to the php site the only difference is which goes first like ^ goes before * etc.

So there has to be something that doesn't work in PHP4 and does work in PHP5, but doesnt generate any errors... Somehow I thnik it's something with the sessions


__________________
PCHF RoX ur SoX
:computer1
PC SmAsH0R

Reply
New! Norton Internet Security 2008 – Download Now Click Here

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


All times are GMT +1. The time now is 03:47 PM.
Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC7
All Graphics & Content Copyright © 2004-2008 - PC Help Forum.com


Back to Top