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
https://forums.phpfreaks.com/topic/96683-variables-pass-across-several-pages/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.