Hi folks, i am having a little trouble with sessions and would appreciate any help. What i am trying to do is have the user login and save the password that they enter into a session so i can use the variable in the next page. But for some reason the variable wont get saved in the session. Below is the code and php session info from the server.

<?php
session_start();
$user="root";
$pass="";
$database="isp";

$use=$_POST['Username'];
$pas=$_POST['Password'];

mysql_connect(localhost,$user,$pass);
@mysql_select_db($database) or die("Unable to select database");

$query="SELECT * FROM userinfo WHERE email = '$use' AND telephone = '$pas'";
$row = mysql_fetch_assoc(mysql_query($query));
mysql_close();

if($row['email'] == $use && $row['telephone'] == $pas){
        $_Session['pas']=$pas;
	echo $_SESSION['pas'];
        //header("location:index-post.php");
	}
	else{
	header("location:LogIn.html");
	}

?>

and the server info:

session
Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 4 4
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0

Recommended Answers

All 8 Replies

instead of trying to save their password y not save their user id like this

$_SESSION['user_id'] = $row['id'];

instead of trying to save their password y not save their user id like this

$_SESSION['user_id'] = $row['id'];

That doesn't work either, it doesn't matter what value i try to put in it is just not getting saved in the session. i tried

$SESSION['pas']="Testing session saving";

and it wont even display that.

Any body else have suggestions?

That doesn't work either, it doesn't matter what value i try to put in it is just not getting saved in the session. i tried

$SESSION['pas']="Testing session saving";

and it wont even display that.

$_SESSION['pas']="Testing session saving";

i think If you are using the latest version of WAMP or PHP, you are using PHP 5. that register_globals is disabled by default. Therefore you should
use the superglobal $_SESSION, instead of session_is_registered and
session_register. Quoting the manual-page of session_register at php.net
( http://nl3.php.net/manual/en/functio...n-register.php)
"If you want your script to work regardless of register_globals, you
need to instead use the $_SESSION array as $_SESSION entries are
automatically registered. If your script uses session_register(), it
will not work in environments where the PHP directive register_globals
is disabled."

put ob_start(); at top of the page. try it.

$_SESSION['pas']="Testing session saving";

i think If you are using the latest version of WAMP or PHP, you are using PHP 5. that register_globals is disabled by default. Therefore you should
use the superglobal $_SESSION, instead of session_is_registered and
session_register. Quoting the manual-page of session_register at php.net
( http://nl3.php.net/manual/en/functio...n-register.php)
"If you want your script to work regardless of register_globals, you
need to instead use the $_SESSION array as $_SESSION entries are
automatically registered. If your script uses session_register(), it
will not work in environments where the PHP directive register_globals
is disabled."

meralikalpana is right you are using $SESSION when it should be $_SESSION.

$SESSION isnt saving to a the session it is saving as a variable, it is like having $CAr or $Name.

Hi , USe like this

<?php 
ob_start("ob_gzhandler");
@session_start();
?>

and

$_SESSION['pas'] =$pas;

I think that will solve the issue ...

Besides from the very obvious as pointed above ($_SESSION) I would also suggest making sure you have cookies enabled. If cookies are disabled then sessions are disabled unless you put the session id in the url. The session id is stored in the variable/constant SID (upper case and no $ symbol) as corrected in the below script.

<?php
session_start();
$user="root";
$pass="";
$database="isp";

$use=$_POST['Username'];
$pas=$_POST['Password'];

mysql_connect(localhost,$user,$pass);
@mysql_select_db($database) or die("Unable to select database");

$query="SELECT * FROM userinfo WHERE email = '$use' AND telephone = '$pas'";
$row = mysql_fetch_assoc(mysql_query($query));
mysql_close();

if($row['email'] == $use && $row['telephone'] == $pas){
        $_SESSION['pas']=$pas;
	echo $_SESSION['pas'];
        //header("location:index-post.php?".SID);
	}
	else{
	header("location:LogIn.html");
	}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.