Problem in Session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ghfazil
Forum Newbie
Posts: 6
Joined: Fri Jun 09, 2006 5:41 am

Problem in Session

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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;
ghfazil
Forum Newbie
Posts: 6
Joined: Fri Jun 09, 2006 5:41 am

Post by ghfazil »

Yes I have firewall that is zonealarm but i didn't put any restriction on apache.
ghfazil
Forum Newbie
Posts: 6
Joined: Fri Jun 09, 2006 5:41 am

Post by ghfazil »

$_SESSION['username'] = $username really worked. Thank alot for your help.

Regards,
Ghazala
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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
Post Reply