Current location: Hot Scripts Forums » Programming Languages » PHP » session problems


session problems

Reply
  #1 (permalink)  
Old 05-20-08, 01:27 PM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 413
Thanks: 12
Thanked 3 Times in 3 Posts
session problems

ok we have got our sessions setup but somethings not right we keep getting errors where it doesnt keep the session and other bits like that !

PHP Code:

include_once "includes.php";

if (! isset(
$_SESSION['id'])){
    if (
$_POST["login_username"] != "" and $_POST["login_password"] != ""){
        
$username $_POST["login_username"];
        
$password $_POST["login_password"];
        
$result mysql_query("select id from user where username='$username' and password='$password'")or die(mysql_error());
        if (
mysql_numrows($result) == 1){
            
$_SESSION['id'] = mysql_result($result,0"id");
        } else {
            echo 
"Wrong username or password";
            exit;
        }    
    } else {
        
header("location:index.php");
        exit;
    }
} else {


}
$data mysql_query("Select * from stats where id=$_SESSION[id]")or die(mysql_error()); 
thats from our home.php and it uses a session.controller.inc.php

PHP Code:

<?

function mysql_session_open($session_path,$session_name){
    
mysql_pconnect("host","user","pass")or die("Can't connect to MySQL server!");
    
mysql_select_db("db_name")or die("Can't connect to MYSQL server!");
}

function 
mysql_session_close(){
return 
1;
}

function 
mysql_session_select($SID) {
    
$query "select value from sessionInfo where SID = '$SID' and expiration > "time();
    
$result mysql_query($query);
    if(
mysql_num_rows($result)){
        
$row mysql_fetch_assoc($result);
        
$value $row['value'];
        return 
$value;
    } else {
        return 
"";
    }
}    

function 
mysql_session_write($SID$value){
$lifetime get_cfg_var("session.gc_maxlifetime");
$expiration time() + $lifetime;
$query "insert into sessionInfo values('$SID','$expiration','$value')";
$result mysql_query($query);
if(! 
$result){
$query "UPDATE sessionInfo set expiration = '$expiration',value='$value' where SID = '$SID' and expiration >"time();
$result mysql_query($query)or die(mysql_error());

}

}


function 
mysql_session_destroy($SID){
    
$query "DELETE FROM sessionInfo where SID = '$SID'";
    
$result mysql_query($query);
}

function 
mysql_session_garbage_collect($lifetime){
    
$lifetime get_cfg_var("session.gc_maxlifetime");
    
$time time() - $lifetime;
    
$query "DELETE FROM sessionInfo where expiration < ".$time;
    
$result mysql_query($query);
    return 
mysql_affected_rows($result);
}

?>
can you see any errors in this or give any info on why its not working

thanks
mike
Reply With Quote
  #2 (permalink)  
Old 05-20-08, 01:45 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Just had a quick glance over it. I noticed this line
PHP Code:

$data mysql_query("Select * from stats where id=$_SESSION[id]")or die(mysql_error());

//TRY IT AS
$data mysql_query("Select * from stats where id={$_SESSION['id']}")or die(mysql_error()); 
I'm not too sure with your sessions, but most have session_start() at the top of the scripts. you may also want to google 'mysql injection' too, since your code is susceptible to it

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #3 (permalink)  
Old 05-20-08, 03:53 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
Ye, use mysql_real_escape_string to prevent mysql injection...

Try echoing things on the screen to if the session even stored, as Jay said do you have session_start() anywhere?
__________________
01010000 01001000 01010000
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Continuing a session on a different server Deansatch PHP 13 01-31-08 12:22 PM
Session Security (Continued from post below) nova912 PHP 1 09-05-06 09:29 AM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
I'm desperate for work, I'll do any work for cheap [PHP/MySQL] Anastas Job Offers & Assistance 17 02-12-06 11:18 AM
urgent: session timeout occurs unexpectedly in ASP.net seemagaur ASP.NET 3 10-11-05 11:10 PM


All times are GMT -5. The time now is 07:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.