Page 1 of 1

PHP login Script help with sessions

Posted: Tue Mar 31, 2009 8:12 pm
by VarwigDude
I have a login script in which it works fine. on my homepage i want it to display the first name of the user. I have it where i can show the username but nothing else.
I have tried different sessions and mysql functions nothing works. Any Suggestions.

My Login page is

Code: Select all

include ("functions.php");
 
session_start();
 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];
 
 
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
 
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' or email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
 
 
$count=mysql_num_rows($result);
 
 
if($count==1){
 
$_SESSION['username'] = $myusername;
session_register("myusername");
session_register("mypassword"); 
header("location:?x=home");
}
else {
echo "Wrong Username or Password";
login();
}
 
ob_end_flush();
My Home page is

Code: Select all

 
<?php
session_start();
 
require_once ACCOUNT_DIR . 'functions.php';
 
session_start();
if(!session_is_registered(myusername)){
login();
}
if(session_is_registered(myusername)){
echo "<a href=\"?x=logout\">Logout</a>\n"; 
echo $_SESSION['username'];
?>
 

Re: PHP login Script help with sessions

Posted: Tue Mar 31, 2009 8:25 pm
by tech603

Code: Select all

$sql="SELECT FirstName FROM $tbl_name WHERE username='$myusername' or email='$myusername' and password='$mypassword'";
I would specify this to grab the name and any other data you need. Then set your session with that value. Cause currently you are only setting the user name not the first name.

Hope that helps

Re: PHP login Script help with sessions

Posted: Tue Mar 31, 2009 8:30 pm
by VarwigDude
i tried

Code: Select all

$query  = "SELECT firstname FROM $tbl_name WHERE username='$myusername' or email='$myusername' and password='$mypassword";
$result2 = mysql_query($query);
while($row = mysql_fetch_row($result2))
{
$firstname    = $row['firstname'];
$row['firstname'] = $_SESSION['firstname'];
} 
 
But this is not working. is everything in the correct order?

Re: PHP login Script help with sessions

Posted: Tue Mar 31, 2009 9:31 pm
by tech603

Code: Select all

$row['firstname'] = $_SESSION['firstname'];


That's backwards :) switching those around looks like it would solve your issue.