Reputation: 11
I am writing a log in page in php, and I am having trouble setting up $_SESSION. I am new to php and I don't know what I am doing wrong. The Script works fine on localhost, but when I push it to the remote server, it does not work. Could it be the php.ini file? Thanks for your help.
<?
start_session();
$dbc = mysqli_connect($host,$name,$dpassword,$database) or die('Error can not connect to corp database');
$q="SELECT * FROM corporate WHERE (email='$theemail' AND password='$md5pass' AND activated = '1')";
$result= mysqli_query($dbc,$q) or die("Error: ".mysqli_error($dbc));;
if(@mysqli_num_rows($result) == 1)
{
//get the entire row
$getrow = mysqli_fetch_array($result);
//also tired
//$_SESSION = mysqli_fetch_array($result, MYSQLI_ASSOC);
//set session, but does not get set!
$_SESSION['lname'] = $getrow['lname'];
$_SESSION['fname'] = $getrow['fname'];
//set cookie for an hour
setcookie("lname", $getrow['lname'], time()+60*60,"/","http://www.limozoor.com",1);
setcookie("fname",$getrow['fname'],time()+60*60,"/","http://www.limozoor.com",1);
//if no header is not sent, send it.
if(!headers_sent())
{
header('Location: http://www.limozoor.com/login/homepage.php');
exit();
}//inner
}//outter
}
?>
php.ini
[Session]
session.save_handler = files
session.save_path = /tmp
session.use_cookies = 1
session.name = sid
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_divisor = 100
session.gc_maxlifetime = 1440
session.bug_compat_42 = 1
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 1
Upvotes: 0
Views: 292
Reputation: 410
It may be just an oversight but the function in your code is incorrect: it is should not be start_session()
but session_start()
.
http://php.net/manual/en/function.session-start.php
Besides that, I don't see anything in your php.ini settings that may cause session not to work.
You should put those lines in your php.ini error_reporting = E_ALL | E_STRICT
and display_errors = On
. It will allow you to see as many error messages as possible.
Finally you can check apache error log to see if you can find any meaningful error messages. By default on Linux it will be in /var/log/apache2/error.log or /var/log/httpd/error.log
Upvotes: 1
Reputation: 11984
Try changing these code segments
start_session();
into
session_start();
and
$_SESSION['lname'] = $getrow['lname'];
$_SESSION['fname'] = $getrow['fname'];
into
if($getrow['lname']!='' && $getrow['fname']!=''){
$_SESSION['lname'] = $getrow['lname'];
$_SESSION['fname'] = $getrow['fname'];
}
Upvotes: 1
Reputation: 16369
Could it be your session start?
you have start_session(), but i think it should be session_start()
Upvotes: 0
Reputation: 2300
Shouldn't you be using:
session_start();
not
start_session();
if that function is not properly called your browser will not actually store any session data.
Upvotes: 0