Page 1 of 1

Problem in Session

Posted: Fri Jun 09, 2006 5:47 am
by ghfazil
Hi,

I am trying to register a variable in session but when i try to retrieve the session value on next page. It gives me empty string. The code worked once but now it is not working. Can any one tell me where i am worng.

<?php

error_reporting(0);
session_start();

$server = "localhost";
$dbuser = "root";
$dbpass = "abcd";
$dbname = "abcd";

$pass = $_REQUEST['txtPwd'];
$login = $_REQUEST['txtEmail'];

if($login != "" and $pass != "")
{
$pass = md5($pass);

mysql_connect($server,$dbuser,$dbpass) or die ("Could not establish connection");
mysql_select_db($dbname);

$query_rsLogin = "SELECT email, pwd, fname, lname FROM customer WHERE pwd='".$pass."' AND email='".$login."'";
$rsLogin = mysql_query($query_rsLogin) or die(mysql_error());

if(mysql_num_rows($rsLogin))
{
while($r=mysql_fetch_array($rsLogin))
$username = $r[fname]." ".$r[lname];
session_register("username");
header('Location: search.php');
}
}

Regards,
Ghazala

Posted: Fri Jun 09, 2006 5:51 am
by Oren
Do you have a firewall? If so, which one?

P.S I don't use session_register(), instead I would do it like this: $_SESSION['username'] = $username;

Posted: Fri Jun 09, 2006 6:04 am
by ghfazil
Yes I have firewall that is zonealarm but i didn't put any restriction on apache.

Posted: Fri Jun 09, 2006 6:10 am
by ghfazil
$_SESSION['username'] = $username really worked. Thank alot for your help.

Regards,
Ghazala

Posted: Fri Jun 09, 2006 6:27 am
by Oren
ghfazil wrote:Yes I have firewall that is zonealarm but i didn't put any restriction on apache.
It doesn't matter... I have Zone Alarm too, and this would block sessions from moving from one page to another on my local server. If I want sessions to move from one page to another on my local server, I have to turn the cookie control off and also to turn the ad blocking off.

P.S On a real server I can set both to the highest level and the sessions would pass. Kinda odd :?

Glad to hear that now it works for you :P