Showing the users name after he logins

Hi guys

I am new to PHP and need som help. I have set up a site that allows a user to log in through a simple form where the data is then send to checklogin.php. Here the data is checked up against my sql database and if the login is correct the user is transfered to the “secret” members only site. All this works fine.
My question is then, how do I get the members site to greet the member with “Hello ‘username’”; of course where the username changes depending on the login.
This is the part where the username and password is checked:

<?php $host="mydbb10.surftown.dk"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="****"; // Database name $tbl_name="members"; // 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 form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $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' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "korrekt.php" session_register("myusername"); session_register("mypassword"); echo "Tak fordi du loggede ind
Redirecter..."; header("location: ../forhandlerservice.php"); } else { echo "Forkert brugernavn eller password"; header("location: ../loginfejl.html"); } ?>

and this is the first line of code on the members site:

<? session_start(); if(!session_is_registered(myusername)){ header("location:login.html"); } ?>

Sorry if I provided to much code, just want to make sure that I don’t forget anything.

Any help is appreciated. Thank you

Save a cookie when the user logs in and have the member site check that the cookie is set and if so show the stuff otherwise redirect them.

Sponsor our Newsletter | Privacy Policy | Terms of Service