Forum Moderators: coopster

Message Too Old, No Replies

cannot pass a session variable

please help.

         

adhu

7:38 am on Aug 30, 2006 (gmt 0)

10+ Year Member




hi...

i tried a simple login functionality. my requirement is ,if the login usermane and password is correct , display the username in the next page(user's page). The username cannot be displayed the next page.

This code works fine in my local machine with PHP Version 5.1.4, but dosent work in my webserver with PHP Version 4.3.4. The username is displayed in the 'userlogin1.php' page when working in local machine.. but not in webserver.

can anyone please sort out the problem for me...

code:

<?php
session_start();
include("conn.php");

// checking the login

$strDB=mysql_connect($strServer,$strUser,$strPwd);
if(!$strDB) die("Cannot connect to Server");
$database=mysql_select_db("$strDatabase",$strDB);

if(isset($_POST['username']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$query = "Select * From security Where Username = ('$username') And password = ('$password')";
$result = mysql_query($query);
if (mysql_num_rows($result)==1)
{
$_SESSION['uname']=$username;
header('Location: userlogin1.php');
}
else
{
$msg="Invalid user";
}
}

mysql_close($strDB);
?>

userlogin.php // this is the page where the username has to be dispalyed

<?php
session_start();
if(!isset($_SESSION['uname']))
{
header("Location: index.php");
}
echo($_SESSION['uname'])?>

Steerpike

10:02 am on Aug 30, 2006 (gmt 0)

10+ Year Member




Just to make sure the basics are covered, the database that you were using on your localhost is installed on the webserver along with the php pages, yes?

henry0

11:22 am on Aug 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adhu, Welcome to WebmasterWorld!

Try removing the parenthesis

<<<
$query = "Select * From security Where Username = '$username' And password = '$password'";
>>>

The way you are using Headers down below the script very top calls for Output Buffering OB
to be turned on in your PHP.ini

Two options either you decide on the side of your OB
Or you just type: On

Depending on traffic and what OB will be performing your site might be just a tad slower.

eelixduppy

4:45 pm on Aug 30, 2006 (gmt 0)



Don't forget to escape your vars!

$username = [url=http://us2.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url]($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$query = "Select * From security Where Username = '$username' And password = '$password'";

;)