Search
Left Quote    By failing to prepare, you are preparing to fail.
- Benjamin Franklin    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Login Issues from Complete Member's System
  This user is offline  sheshazam
  Subject: "Login Issues from Complete Member'..." Posted: @ 7:22 pm on Nov 30 2005   
Member #: 111
Rank: User - (5)
Since: 11/30/05
Posts: 5
From: Irvine, CA

I'm using your tutorial to learn how to create a members system.

Register: Success
Login: Limited Success
Content Page: Limited Success
Logout: Success

I'm not sure why my user name is not appearing and why the page still comes up if I logout and call it back manually. Your thoughts?

Below is my page header which appears on my content page: content.php

Code:
<?
ob_start();
session_start( );
require_once(&q uot;db_connect. php";

$whatsession=($ _SESSION['logge d_in']);
$whatcookie=($_ COOKIE['login_c ookie']);

//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` = '".addslas hes($user).&quo t;'";
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;;



}
?>



Below is the code for my content.php page


Code:
<?
include ("page_hea der.php";

echo "Hello $user <----Usernam e should appear here. This is a page of content.<br& gt;<br>&q uot;;
echo "This is the session. Logged in is 1 and logged out is 0: <br><b r>$whatsessi on";
echo "<br> ;<br>This is the cookie:<br&g t;<br> $whatcookie&quo t;;
?>
<br><b r>
<a href="logo ut.php"> ;Click here to log out</a>


On a successful login my page looks something like this:

Hello <----Usernam e should appear here. This is a page of content.

This is the session. Logged in is 1 and logged out is 0:

1

This is the cookie:



Click here to log out


    Viewed: 9,496 Times | Reply to This | To top
  This user is offline  sheshazam
  Subject: "re: Login Issues from Complete Memb..." Posted: @ 7:28 pm on Nov 30 2005    
Member #: 111
Rank: User - (5)
Since: 11/30/05
Posts: 5
From: Irvine, CA

Just in case: Here is my login. Just as easily the culprit. I'll keep digging. Fascinating.


Code:

<?
ob_start();
require_once(& quot;db_connect .php";
include(" page_header.php ";

if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: content.php&qu ot;
} //end if logged in

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

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";

//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie(&quo t;login_cookie ", $joined, 2147483647, '/', '.www.yoursite .com');
} //end if

//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify your username and password are correct."< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: content.php&qu ot;

} else {
//show login form
?>

<form name="log in" method="p ost" action="& lt;? $_SERVER['PHP_ SELF']; ?>"> ;
<table> <tr>
<td>Usern ame:<input type="tex t" id="usern ame" name="use rname"> ;</td>
</tr>
<tr>
<td>Passw ord:<input type="pas sword" id="passw ord" name="pas sword"> ;</td>
</tr>
<tr>
<td>Submi t: <input type="sub mit" value="Su bmit" name="sub mit" id="submi t">< ;/td>
</tr>
<tr>
<td>Remem ber? <input type="che ckbox" name="sta y_in[]" checked=" yes">& lt;/td>
</tr>
</table>< br /> </form>&l t;?
}//end else
?>




    Viewed: 9,433 Times | Reply to This | To top
  This user is offline  sheshazam
  Subject: "re: Login Issues from Complete Memb..." Posted: @ 7:30 pm on Nov 30 2005    
Member #: 111
Rank: User - (5)
Since: 11/30/05
Posts: 5
From: Irvine, CA

Love the emoticons in the code.




    Viewed: 9,429 Times | Reply to This | To top
  This user is offline  sheshazam
  Subject: "re: Login Issues from Complete Memb..." Posted: @ 7:33 pm on Nov 30 2005    
Member #: 111
Rank: User - (5)
Since: 11/30/05
Posts: 5
From: Irvine, CA

Some more info I found when hacking around.

If I include the page_header.php in the login it logs me in but won't show username.

If I comment out the page_header.php include in login it does show my username....but it's guest.

So close yet so far. Thanks!




    Viewed: 9,426 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Login Issues from Complete Memb..." Posted: @ 11:01 pm on Nov 30 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

 shesha zam said...

< i>Love the emoticons in the code.

pretty, arent they?

i think one problem could be here:

$whatsession=($ _SESSION['logg ed_in']);
$whatcookie=($_ COOKIE['login_ cookie']);

i dont think you need the ( or ) after the = sign for each variable.

Now, I also noticed you set $user = $_SESSION['use rname']; and such. No need to do that, its a session variable for a reason, so call the user by $_SESSION['use rname']; instead of $user, and see how that works out (on your content page).

Also, no reason to print the cookie, is only the username and an encrypted password.



Edited at 11:05:10 pm on 11/30/05


-bs0d | AllSyntax.com

    Viewed: 9,421 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