Jump to content

Display name on site after login


ow-design

Recommended Posts

Hi, I am 16yrs old and need some help with finsihing a php site i am building.

 

Basically at the moment i have a login form which check users details etc etc and creates a cookie based on username to dsiplay throughout the site.

 

But how do i get their real name from the database with just a username and password from loigin form?

 

Could somebody pist some code pleae :)

 

Thank You -- I have looked everywhere and i bet its really simple too but i am stuck and need some help.

Link to comment
Share on other sites

sessions and cookies are very similar...

cookies store on the computer, sessions store on the server

 

that much said... cookies cannot contain arrays so easily... sessions can...

 

when you do the login, just store their data into $_SESSION ($_SESSION[user]=$row) then anywhere on the page, you can use any of that information via $_SESSION[user][fullname]... for example :-)

Link to comment
Share on other sites

Okay I have a login page: login.php which simply takes username & password and sends it to checklogin.php... Code below. See at the moment i am using cookies to store username and display that so on the pages it says welcome ________ (gets cookie name) but i would really like it to say welcome ____ (real name)

 

Code below...Thanks!

<?php
setcookie("user", $_POST['username'], time()+3600);

$host="localhost"; // Host name 
$username="myusername"; // Mysql username 
$password="mypassword"; // Mysql password 
$db_name="raphkat.co.uk_cart"; // Database name 
$tbl_name="users"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$username=$_POST['username']; 
$password=$_POST['password']; 

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row

if($count==1){
// Register $username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password"); 
header("location:index.php");
}
else {
echo "You have entered an incorrect username... Please try again";
}
?>

Link to comment
Share on other sites

too complicated...

 

<?php
$host="localhost"; // Host name 
$username="myusername"; // Mysql username 
$password="mypassword"; // Mysql password 
$db_name="raphkat.co.uk_cart"; // Database name 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$username=addslashes(strip_tags($_POST['username']));
$password=md5($_POST['password']);

$result=mysql_query("SELECT * FROM `users` WHERE `username`='$username' and `password`='$password' LIMIT 1");
$row=mysql_fetch_array($result);

if(!empty($row)){
$_SESSION[user]=$row;
header("location:index.php");
}else{
echo "You have entered an incorrect username... Please try again";
}
?>

Link to comment
Share on other sites

Okay no i forgot that... But now i am getting this message

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/raphkat/public_html/about.php:6) in /home/raphkat/public_html/about.php on line 17

 

HELP!!! :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.