Search
Left Quote    Wise men speak because they have something to say; Fools because they have to say something.
- Plato (427-347 B.C.)    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Member Login
  This user is offline  wicky
  Subject: "Member Login" Posted: @ 3:38 pm on Oct 12 2006   
Member #: 217
Rank: User - (1)
Since: 10/08/06
Posts: 1

Hey I am having problems with the Member login script, its a great tutorial, and allows me to access the page as if I was logged in, however, when trying to show the user logged in, it appears as guest, and also, if I try to use the log out script, it basically says I am not logged in to log out... here is my coding...

My login.php

Code:
<? ob_start();
require('db_con nect.php');
session_start() ;
if(isset($_SESS ION['username'] ) && isset($_SESSION ['password'])) {
//REDIRECT TO USERS PROFILE...
header("Lo cation: page_header.php ";
} //end if logged in

//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['use rname']) die("Error : You must enter your username before logging in.";
if(!$_POST['pas sword']) die("Error : You must enter your password before logging in.";

//set cookie if checked
if(!empty($_POS T['stay_in'])) {
$joined =''.$_POST['use rname'].'[]'.md 5($_POST['passw ord']).'';
setcookie('logi n_cookie', $joined, 2147483647, '/', 'page_header.ph p');
} //end if
//verify user...
$get_user = mysql_query(&qu ot;SELECT * FROM `members` WHERE username = '".$_POST[ 'username'].&qu ot;' AND

user_password = '".md5($_P OST['password'] )."'"< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Login Failure: An error occured, please verify your username and password are correct.";
//set session variables
$_SESSION['logg ed_in'] = 1;
$_SESSION['user name'] = $_POST['usernam e'];
$_SESSION['pass word'] = $_POST['passwor d'];
session_write_c lose();

header("Lo cation: member.php" ;

} else {
//show login form
?>
<form name="logi n" method="po st" action="&l t;? $_SERVER['PHP_S ELF']; ?>">
<table> <tr>
<td>Usern ame:<input type="text " id="userna me" name="user name">& lt;/td>
</tr>
<tr>
<td>Passw ord:<input type="pass word" id="passwo rd" name="pass word">& lt;/td>
</tr>
<tr>
<td>Submi t: <input type="subm it" value="Sub mit" name="subm it" id="submit "></ td>
</tr>
<tr>
<td>Remem ber? <input type="chec kbox" name="stay _in[]" checked="y es">< ;/td>
</tr>
</table>< br /> </form> <?
}//end else
?>




and my member.php

Code:
<html> <body>
<? ob_start();
require('db_con nect.php');
include('page_h eader.php');
//check cookie
if ($_SESSION['log ged_in'] == 1 && isset($_COOKIE[ 'login_cookie'] )) {
list($user, $pass) = explode('[]', $_COOKIE['login _cookie']);
$qu = mysql_query(&qu ot;SELECT `user_password` FROM `members` WHERE `username` = '"($user)& quot;'";
if (mysql_num_rows ($qu) == 1) {
$passw = mysql_fetch_obj ect($qu);
if ($passw->use r_password == $pass) {
$_SESSION['logg ed_in'] == 1;
$_SESSION['user name'] == $user;
$_SESSION['pass word'] == $pass;
}
}
}

if(!isset($_SES SION['username' ]) && !isset($_SESSIO N['password'])) {
$_SESSION['logg ed_in'] == 0;
$user = "Guest&quo t;;
}
print_r($user);
echo "$user&quo t;;

?>


</body> </html>



Help would be greatly apprciated, as I cant understand where I have gone wrong?


    Viewed: 5,763 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Member Login" Posted: @ 4:09 pm on Oct 12 2006    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

in your member.php file, you need to do session_start() before trying to access $_SESSION. Also, your ob_start() needs to be before <html> and <body>




please note that the above post is likely made up in its entirety.

    Viewed: 5,756 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: Member Login" Posted: @ 3:55 am on Oct 13 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

Thats not the only problem hes having, I had the same problem with this but I fixed it easily.


Code:

$user = $_SESSION['use rname']
< br>
try that to retrieve username.



Edited at 03:57:39 am on 10/13/06


woohoo!

    Viewed: 5,747 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Member Login" Posted: @ 2:44 pm on Oct 13 2006    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

< i>//check cookie
if ($_SESSION['lo gged_in'] == 1 && isset($_COOKIE[ 'login_cookie '])) {

here if the user is already logged in (the $_SESSION part of the check), there's no reason to look at the cookie.

also ki is right -- the only way $user gets set in your code is from the login_cookie cookie, or if nobody's logged in and it gets set to 'Guest'




please note that the above post is likely made up in its entirety.

    Viewed: 5,739 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank