Jump to content

variables pass across several pages


evios

Recommended Posts

hi, i am the newbie here...i am currently working in php, newbie as well...

i am doing a form, so at the login page i will need a user to login using valid username and password,

the data will then stored in $username and $password. Action of the form link to logincheck.php, here the variables still contain the data. However, link from this page, when i echo it, it seems blank, below will be the code i use:

<div><label>Name:<?php echo $username;?></label><br></div>

i'd tried cookies but in vain. Any clue here? Thanks

Link to comment
Share on other sites

Hi

 

You would need to Validate the data being passed over to the form then store the Data as a session. The session will last until you destroy it using session_destroy() or until the user closes there Browser Window.

 

<?php
//Start the session, this has to be at the very top of your PHP script, so best to place it on your Index page before any headers are sent 
session_start();

//Get the submitted data from the User
$username = $_POST['username'];

//Error check the user name for Invalid charcters i.e Preg Match I won't put that here im meant to be working 

//Register the session
session_register('username');

//Store The Username
$_SESSION['username'] = $username;

//Now to say output the User name in any script on your site
echo $_SESSION['username'];


?>

 

Hope this helps.

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.