PHP login Script help with sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VarwigDude
Forum Newbie
Posts: 12
Joined: Tue Mar 31, 2009 8:08 pm

PHP login Script help with sessions

Post 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'];
?>
 
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: PHP login Script help with sessions

Post 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
VarwigDude
Forum Newbie
Posts: 12
Joined: Tue Mar 31, 2009 8:08 pm

Re: PHP login Script help with sessions

Post 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?
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: PHP login Script help with sessions

Post by tech603 »

Code: Select all

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


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