Page 1 of 1

Session problem, please help me!!!

Posted: Fri Feb 06, 2004 3:17 am
by askme
Here is the simple user authentication I have made and try to verify the name and password from MySql database. The problem is that I cannot pass the session variable between pages, I mean to SUCCESS.PHP page.
All pages codes are given below, It has 3 pages,
1. LOGIN.PHP
2. AUTHENTICATE.PHP
3. SUCCESS.PHP

Here are the codes:

LOGIN.PHP

Code: Select all

<html>

<head>
<title>login Page</title>
</head>
<body>

<form method="POST" action="authenticate.php">
  
<p>Name:<input type="text" name="name" size="20"></p>
<p>Password:<input type="password" name="password" size="20"></p>
<p><input type="submit" value="Submit"><input type="reset" value="Reset"></p>

</form>
</body>
</html>
AUTHENTICATE.PHP

Code: Select all

<?php 
session_start(); 
$name = $HTTP_POST_VARS&#1111;'name'];
$password = $HTTP_POST_VARS&#1111;'password'];

$HTTP_SESSION_VARS&#1111;'name']=$name;
$HTTP_SESSION_VARS&#1111;'password']=$password;


  //connect to the database... 
 
 mysql_connect(HOST, USER, PASS); 
 mysql_select_db(DB); 
 
 //...and get number of result matched 
 
$result = mysql_query("SELECT from login WHERE name='&#123;$HTTP_POST_VARS&#1111;'name']&#125;' AND password='&#123;$HTTP_POST_VARS&#1111;'password']&#125;'"); 

$rows=mysql_mun_rows($result)

if ($rows > 0)
&#123;

//Redirect the user to success page to prompt him 

session_register('$name');  
require('success.php');
exit; 

       &#125; 
else
     &#123;

//unsuccessful login 

echo 'sorry, you are not allowed, try again';
require('login.php');
exit;
 
    &#125; 
?>

SUCCESS.PHP

Code: Select all

<?php 

session_start(); 
echo 'Welcome to Autherized Area';
echo 'you are logged as';
echo $HTTP_SESSION_VARS&#1111;'name'];
  
?>
Please let me know, What is the problem, I could not get the session variable at SUCCESS.PHP page.

Posted: Fri Feb 06, 2004 3:21 am
by twigletmac
First question - what version of PHP are you using?

Mac

Posted: Fri Feb 06, 2004 3:31 am
by askme
I am using PHP 4.0.1 on Windows XP. I have Installed from PHP triad for Windows!!!

Posted: Fri Feb 06, 2004 3:39 am
by Michael 01
This may seem trivial, but you forgot the semicolon at the end of the sql statement $rows=mysql_mun_rows($result)

Sometimes, and Im not sure if it matters in this case or not so dont sue me, statements will leak by making a person think everything is working but they are not. Especially if you have any parse error settings off...etc..
The reason I think it could be a problem, is because you use it for a comparison in your "if" statement. In reality, it could be returning nothing and simply exiting out without properly saving the session register.

Posted: Fri Feb 06, 2004 3:51 am
by Michael 01
What I should of done was post a example of what I mean.

I always use the empty function because having a set number can sometimes cause problems with SQL statements, but..if it is empty, she should just quit rite there.

Code: Select all

if (empty($rows )) &#123;
   echo 'There was nothing returned from the DB';
   exit;
&#125;

Posted: Fri Feb 06, 2004 4:14 am
by twigletmac
4.0.1 are you sure? If so you should really upgrade to 4.3 as 4.0 is now very outdated and will make it difficult for you to manage sessions.

Mac

Posted: Fri Feb 06, 2004 4:33 am
by askme
Great Advice from you people, I will try to upgrade my PHP and then try the code again, by the way where can I get PHP Triad Upgrade!!!

(Because it is very easy to Install, Apache, MySql, and PHP together, all it configure by itself.)

Posted: Fri Feb 06, 2004 7:56 am
by Illusionist
maybe a couple thigns here:

mysql_mun_rows() ? try mysql_num_rows()

and in your SELECT query, add a * between SELECT and FROM

Posted: Fri Feb 06, 2004 9:05 am
by devork
also noticed that
session_register("$name") notation should be used
session_register("name")
write only the name of variable without '$' sign

Posted: Fri Feb 06, 2004 1:33 pm
by Michael 01
Illusionist wrote:maybe a couple thigns here:

mysql_mun_rows() ? try mysql_num_rows()

and in your SELECT query, add a * between SELECT and FROM

damn man, good eye!!
That one slipped right through the cracks.

Wow...its funny how a little tiny mistake in spelling can be so difficult to find sometimes, and I am sure that with that problem solved, coupled with some of the other things mentioned in this thread, he will be back up in running in no time.

Posted: Fri Feb 06, 2004 1:35 pm
by Michael 01
Lol...what is funnier yet, I copy/pasted that sucker as is in my above post regarding the semi-colon.

Posted: Thu Feb 12, 2004 12:46 am
by askme
It was typing mistakes,

Code: Select all

mysql_mun_rows() --------->mysql_num_rows() 

and 

 SELECT  * FROM login WHERE ...........
But the problem is still I cannot get my problem solved, cannot pass session variable to other pages.

By the way there is any equavalent code in PHP for this ASP code

Code: Select all

Response.redirect('login.asp');

Posted: Thu Feb 12, 2004 1:15 am
by no1shah
HEllo Friend
Two days earlier i was also facing the same problem,
First is u can then upgrade ur php version sither 4.3.4/4.3.3

Next check the php.ini file and see whether register_global is on or off.
By default it should be off and i reccomend u to use it as off,in version 4.3.4 create the session using $_SESSION and use $_POST.
r u still getting prob.sssssssssss

Posted: Thu Feb 12, 2004 1:52 am
by mahara
askme wrote:Great Advice from you people, I will try to upgrade my PHP and then try the code again, by the way where can I get PHP Triad Upgrade!!!

(Because it is very easy to Install, Apache, MySql, and PHP together, all it configure by itself.)
So, what is the version of PHP you are using now?

redirects in php

Posted: Thu Feb 12, 2004 3:44 am
by weecol
regarding the query on how to do redirect headers in php
try calling header with location("location: <URL>");
according to php.net it handles the 3xx header as well but you can set it using header("Status: 3xx <approreate string>"); 8)

When I need a solution I will first look up php.net

RTFM