Jump to content

Archived

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

legohead6

reload to new page

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
ya i coded the pass, also say i wanted to retrieve the pass...what would i use?(never used a session before)

thanks
Matt

[!--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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
You can if you are using it in an if statemnt but its safe to use it if you just checking for other vairbles

Share this post


Link to post
Share on other sites

×

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.