legohead6 Posted May 18, 2006 Share Posted May 18, 2006 hi i have a login thingy(not prfessional but works) and it validates it on the same page then i want it if sucessfull(already setup) to automaticly go to the new page witch is "main.php?user=$user&pass=$pass" but i cant get it to automaticly go(without clicking a link) Quote Link to comment https://forums.phpfreaks.com/topic/9900-reload-to-new-page/ Share on other sites More sharing options...
.josh Posted May 18, 2006 Share Posted May 18, 2006 first off, you do not want to send information like the user's name and password through the url. but, assuming that you have no html output before the validation, you can use the header function (example):[code]<?php session_start(); if ($_POST['user'] and $_POST['pass']) { $results = mysql_query('select * from table where username='".$_POST['user']."' and password = '".$_POST['pass']."'"); if (mysql_fetch_rows($results) == 1) { $_SESSION['info'] = mysql_fetch_array($results); header ('location: blah.php'); exit; } else { echo 'login failed'; }[/code]i added in session_start(); and then creating a session variable that holds the user's info as an alternative method of passing the information via url. on your target page (blah.php) you would start it off with session_start(); as well. then you can access the information through the info session variable. Quote Link to comment https://forums.phpfreaks.com/topic/9900-reload-to-new-page/#findComment-36806 Share on other sites More sharing options...
legohead6 Posted May 18, 2006 Author Share Posted May 18, 2006 ya i coded the pass, also say i wanted to retrieve the pass...what would i use?(never used a session before)thanksMatt[!--quoteo(post=374863:date=May 17 2006, 11:39 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 17 2006, 11:39 PM) [snapback]374863[/snapback][/div][div class=\'quotemain\'][!--quotec--]first off, you do not want to send information like the user's name and password through the url. but, assuming that you have no html output before the validation, you can use the header function (example):[code]<?php session_start(); if ($_POST['user'] and $_POST['pass']) { $results = mysql_query('select * from members where username='".$_POST['user']."' and password = '".$_POST['pass']."'"); if (mysql_fetch_rows($results) == 1) { $_SESSION['info'] = mysql_fetch_array($results); header ('location: blah.php'); exit; } else { echo 'login failed'; }[/code]i added in session_start(); and then creating a session variable that holds the user's info as an alternative method of passing the information via url. on your target page (blah.php) you would start it off with session_start(); as well. then you can access the information through the info session variable.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/9900-reload-to-new-page/#findComment-36899 Share on other sites More sharing options...
eddedwards Posted May 18, 2006 Share Posted May 18, 2006 just a side question for you.this code: if ($_POST['user'] and $_POST['pass']) {is that shorthand for:if (isset($_POST['user']) and isset($_POST['pass'])ive always used isset to check my postvars.can i get away with just doing it the way you wrote? Quote Link to comment https://forums.phpfreaks.com/topic/9900-reload-to-new-page/#findComment-36907 Share on other sites More sharing options...
mjozwiak Posted May 19, 2006 Share Posted May 19, 2006 You can if you are using it in an if statemnt but its safe to use it if you just checking for other vairbles Quote Link to comment https://forums.phpfreaks.com/topic/9900-reload-to-new-page/#findComment-37039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.