|
 |
|
 |
 |
03-17-2008, 10:00 AM
|
#1 (permalink)
|
|
Recruit
Join Date: Mar 2008
Posts: 4
|
Login with Session Problem
Hi I have followed the instructions on the " Login with Session " thread but i do get blank page. what would be the problem?
Thanks
__________________
|
|
|
03-17-2008, 06:31 PM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
is error reporting turned on? for example, if you make a syntax error, do you see errors on your screen? if not, you need to turn error_reporting on in the php.ini file.
__________________
testing 1 2 3
|
|
|
03-17-2008, 07:54 PM
|
#3 (permalink)
|
|
Senior Contributor
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
|
Or just alter your script, e.g.
PHP Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
session_start();
...
Better yet is to set 'log_errors' and 'error_log' in your php.ini to log everything from every script. This is what you'll want to do eventually anyway.
It may be you have a fatal error, some sort of syntax problem that is causing PHP to not parse the page at all.
Is there anything revealed in the 'view source' option of your browser? Any HTML code shown? Or just a blank page?
__________________
|
|
|
03-18-2008, 01:25 AM
|
#4 (permalink)
|
|
Recruit
Join Date: Mar 2008
Posts: 4
|
thanks for your responses
i have altered the script as you said now i get this errors:
Notice: Undefined index: username in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 11
Notice: Undefined index: username in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 16
Notice: Undefined variable: username in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 30
Notice: Undefined variable: password in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 30
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 30
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 30
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 33
You are not authenticated. Please login.
The script is this:
PHP Code:
<?php
// Login & Session example by sde
// auth.php
error_reporting(E_ALL);
ini_set('display_errors',1);
// start session
session_start();
// convert username and password from _POST or _SESSION
if($_POST["username"])
{
$username=$_POST["username"];
$password=$_POST["password"];
}
elseif($_SESSION["username"])
{
$username=$_SESSION["username"];
$password=$_SESSION["password"];
}
// start and register session variables
session_register("username");
session_register("password");
// connect to database
include("connect.php");
// query for a user/pass match
$result=mysql_query("select * from users where username='" . $username . "' and password='" . $password . "'");
// retrieve number of rows resulted
$num=mysql_num_rows($result);
// print login form and exit if failed.
if($num < 1){
session_destroy();
echo "You are not authenticated. Please login.<br><br>
<form method=POST action=index.php>
username: <input type=text name=\"username\">
password: <input type=password name=\"password\">
<input type=submit>
</form>";
exit;
}
?>
I hope you appreciate my question.
I am a newbee
thanks
__________________
|
|
|
03-19-2008, 12:57 PM
|
#5 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
Here are some quick hints at debugging those error messages:
Quote:
|
Undefined index: username in D:\wamp\www\inc\TMPh1hlhxx6mm.php on line 11
|
"on line 11" means, literally, that this particular error occured literally on the 11th line of the file "D:\wamp\www\inc\TMPh1hlhxx6mm.php". If we jump to that line, we see it is:
"Undefined index" means that in an array, you are attempting to use a key that does not exist. In this case, the array is "$_POST".
Here's something to think about. $_POST is filled with data when a form is submitted. What happens when you load you browse to the login page for the first time, before you've submitted any login information?
|
|
|
03-19-2008, 03:41 PM
|
#6 (permalink)
|
|
Recruit
Join Date: Mar 2008
Posts: 4
|
thanks
Quote:
Originally Posted by Belisarius
Here are some quick hints at debugging those error messages:
"on line 11" means, literally, that this particular error occured literally on the 11th line of the file "D:\wamp\www\inc\TMPh1hlhxx6mm.php". If we jump to that line, we see it is:
"Undefined index" means that in an array, you are attempting to use a key that does not exist. In this case, the array is "$_POST".
Here's something to think about. $_POST is filled with data when a form is submitted. What happens when you load you browse to the login page for the first time, before you've submitted any login information?
|
hi. i knew that submitted keyword was not recegnised when it was submitted. but i did not understand what you mean by
Quote:
|
What happens when you load you browse to the login page for the first time, before you've submitted any login information?
|
sorry. can you please tell me what you mean by that sentence if possible with an example?
thank you
__________________
Last edited by Belisarius : 03-19-2008 at 05:25 PM.
|
|
|
03-19-2008, 05:34 PM
|
#7 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
POST data is sent when you submit a form (usually by pressing on a button labelled "Submit" or "Login" or somesuch) with the "action=POST" property. If you simply load up a PHP page, the $_POST array will be empty because no form has been submitted.
So, if you go to your "TMPh1hlhxx6mm.php" file in your browser, you haven't actually submitted any POST data, and $_POST is empty. However, your script assumes it isn't. For instance, look at the following statement you have on line 11:
$_POST["username"] does not exist - the $_POST array is empty. PHP gives you an error and the "if" statement fails.
Likewise, if this is the first time you have accessed this page, no session variables have been set. So the following elseif:
Quote:
|
elseif($_SESSION["username"])
|
will likewise fail, because $_SESSION is empty. And if both clauses fail, $username and $password are never set.
|
|
|
03-19-2008, 06:05 PM
|
#8 (permalink)
|
|
Recruit
Join Date: Mar 2008
Posts: 4
|
.
Quote:
Originally Posted by Belisarius
POST data is sent when you submit a form (usually by pressing on a button labelled "Submit" or "Login" or somesuch) with the "action=POST" property. If you simply load up a PHP page, the $_POST array will be empty because no form has been submitted.
So, if you go to your "TMPh1hlhxx6mm.php" file in your browser, you haven't actually submitted any POST data, and $_POST is empty. However, your script assumes it isn't. For instance, look at the following statement you have on line 11:
$_POST["username"] does not exist - the $_POST array is empty. PHP gives you an error and the "if" statement fails.
Likewise, if this is the first time you have accessed this page, no session variables have been set. So the following elseif:
will likewise fail, because $_SESSION is empty. And if both clauses fail, $username and $password are never set.
|
honestly, i liked your explanation but do you know the solution? i have to use the login script with session. thanks.
__________________
|
|
|
03-20-2008, 01:23 AM
|
#9 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
Well, why don't you suggest a solution. By trying to debug the problem yourself, you'll get a better understanding of what's going on.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 08:07 PM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|