Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-17-2008, 10:00 AM   #1 (permalink)
hasansahip
Recruit
 
Join Date: Mar 2008
Posts: 4
hasansahip is on a distinguished road
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
__________________
hasansahip is offline   Reply With Quote
Old 03-17-2008, 06:31 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 03-17-2008, 07:54 PM   #3 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
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?
__________________
bdl is offline   Reply With Quote
Old 03-18-2008, 01:25 AM   #4 (permalink)
hasansahip
Recruit
 
Join Date: Mar 2008
Posts: 4
hasansahip is on a distinguished road
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
__________________
hasansahip is offline   Reply With Quote
Old 03-19-2008, 12:57 PM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
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:
Quote:
if($_POST["username"])
"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?
__________________
GitS
Belisarius is offline   Reply With Quote
Old 03-19-2008, 03:41 PM   #6 (permalink)
hasansahip
Recruit
 
Join Date: Mar 2008
Posts: 4
hasansahip is on a distinguished road
thanks

Quote:
Originally Posted by Belisarius View Post
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.
hasansahip is offline   Reply With Quote
Old 03-19-2008, 05:34 PM   #7 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
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:
Quote:
if($_POST["username"])
$_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.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 03-19-2008, 06:05 PM   #8 (permalink)
hasansahip
Recruit
 
Join Date: Mar 2008
Posts: 4
hasansahip is on a distinguished road
.

Quote:
Originally Posted by Belisarius View Post
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.
__________________
hasansahip is offline   Reply With Quote
Old 03-20-2008, 01:23 AM   #9 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
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.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to block parallel login? Anisuzzaman PHP 1 02-18-2007 01:44 AM
A small problem in the output the_master Standard C, C++ 1 12-17-2006 09:09 AM
online bank login not secure sde Lounge 2 12-06-2004 03:08 PM
login session help please Namraw PHP 2 09-14-2004 03:26 PM
check if session variable is null? sde Java 3 07-07-2004 12:27 PM


All times are GMT -8. The time now is 08:07 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle