Jump to content

Archived

This topic is now archived and is closed to further replies.

WilsonC

Need help...strange problems with sessions.

Recommended Posts

Hi, i've been having problems with getting some sessions to work for me:

Initially, i had this code:

[code]
<?php
session_name(login_session);
session_start();
include 'dataconn.php';

// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];

if((!$username) || (!$password)){
    echo "Please enter ALL of the information! <br />";
    include 'loginform.htm';
    exit();
}

$sql = mysql_query("SELECT AuthorNo, AuthorID, Email FROM Author WHERE AuthorID='$username' AND Pwd='$password' AND Status='1'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){

    $row = mysql_fetch_array($sql);
    $today = time();
    $MySQLdate=date(YmdHis,$today);
    $_SESSION['author']=$row['AuthorNo'];
    $_SESSION['sessionLogin'] = $row[AuthorID];
    $_SESSION['sessionEmail'] = $row[email];
    $_SESSION['sessionLogintime'] = $MySQLdate;


    mysql_query("UPDATE Author SET Lastlogin='".$MySQLdate."' WHERE AuthorNo='".$_SESSION['author']."'");

    echo "You have successfully logged on, ".$_SESSION['sessionLogin']." at ".$_SESSION['sessionLogintime']."" ;

} else {
    echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />
        Please try again!<br />";
    include 'loginform.htm';
}

session_write_close();

mysql_close();
?>

[/code]

The above page seemed to work perfectly fine. However, if i added a hyperlink to, say "logintester.php",
and clicked on it:

[code]
<?php
error_reporting(1);
session_name(login_session);
session_start();
if (isset($_SESSION['sessionLogin'])){
         $login = $_SESSION['sessionLogin'];
}else{
         $login = "Not Set";
}

echo "Welcome ". $login ." ";

?>
[/code]

It would return "Welcome Not Set", meaning the values of the session were not accessible on this next page. After scrounging through numerous forums and php sites, and trying various different approaches suggested by different people, i still could not get it to work. I tried testing my sessions with the following script:

[code]
<?php
if (session_id() == "") {
  session_start();
}
error_reporting(1);
session_register('count');
$_SESSION['count']=1;
echo $_SESSION['count'];
$_SESSION['count']++;
echo $_SESSION['count'];
echo SID;
session_write_close();
?>
[/code]

The first time the above script is run, it returns "12PHPSESSID=blablabla". Subsequent refreshes, however, returned just "12".

I've an incredibly strong feeling that this is caused by a really stupid oversight on my part, but i'm really getting frustrated at this. Any help would be deeply appreciated. I even tried switching webhosts but to no avail. For more information i'm using Byethost and infonet.com as testing servers for this.

Thanks in advance for any help anyone can give me.

Share this post


Link to post
Share on other sites

×

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.