Log in, transferring variables

Hi,
I am really stuck on this one. Is it possible to transfer variables? If so how would I implement it into my code? At the moment a user can log in successfully, but I would like it to say, welcome “username here”. How would I do this if the welcome page is a different page to the log in page and will there for not have the required variables.
Here is the code for my login page:

[php]

<?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select database. 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 $usr = $_POST['Username']; $pas = $_POST['Password']; // To protect MySQL injection $usr = stripslashes($usr); $pas = stripslashes($pas); $usr = mysql_real_escape_string($usr); $pas = mysql_real_escape_string($pas); $sql="SELECT * FROM $tbl_name WHERE usr='$usr' and pas='$pas'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $usr and $pas, table row must be 1 row if($count==1){ // Register $usr, $pas and redirect to file "login_success.php" session_register("usr"); session_register("pas"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> [/php]

And here is the code for my login_success page:

[php]<?php
session_start();
// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!session_is_registered(usr)){
header(“location:php.html”);
}
?>

You have successfully logged in!
Welcome <?php //CODE HERE TO SAY THE USERNAME OF THE LOGGED IN ACCOUNT ?> [/php]

So how would I transfer the value of $usr from login.php to login_success.php and print it out saying Welcome “username”?

Many thanks for your time.

[php]PHP Code: [Select]

<?php session_start();// Check if session is not registered, redirect back to main page. // Put this code in first line of web page. if(!session_is_registered(usr)){ header("location:php.html"); // redirect to php.html I am guessing this is php.html } ?> You have successfully logged in!
Welcome <?php echo $usr;?> or <?phpecho $_SESSION['usr'];?> [/php]

Use sessions.

Login page: (right before the redirection at the end)
[php]$_SESSION[‘user’] = $usr;[/php]

Success page: (put this before your welcome message)
[php]$user = $_SESSION[‘user’];[/php]

Success page: (put this where that HTML part starts)
[php]

You have successfully logged in!
<?php echo "Welcome $user!"; ?> [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service