evios Posted March 18, 2008 Share Posted March 18, 2008 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 More sharing options...
berridgeab Posted March 18, 2008 Share Posted March 18, 2008 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 https://forums.phpfreaks.com/topic/96683-variables-pass-across-several-pages/#findComment-494774 Share on other sites More sharing options...
evios Posted March 18, 2008 Author Share Posted March 18, 2008 hey...thanks bro..it works!!! Link to comment https://forums.phpfreaks.com/topic/96683-variables-pass-across-several-pages/#findComment-494832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.