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!
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
<?php
session_start();
$name = $HTTP_POST_VARSї'name'];
$password = $HTTP_POST_VARSї'password'];
$HTTP_SESSION_VARSї'name']=$name;
$HTTP_SESSION_VARSї'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='{$HTTP_POST_VARSї'name']}' AND password='{$HTTP_POST_VARSї'password']}'");
$rows=mysql_mun_rows($result)
if ($rows > 0)
{
//Redirect the user to success page to prompt him
session_register('$name');
require('success.php');
exit;
}
else
{
//unsuccessful login
echo 'sorry, you are not allowed, try again';
require('login.php');
exit;
}
?>
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.
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.
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.
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
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>");
When I need a solution I will first look up php.net