Jump to content

reload to new page


legohead6

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)
Link to comment
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.
Link to comment
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]
Link to comment
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?
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.