Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send a form variables when loads a page automaticaly

Status
Not open for further replies.

egmweb

Programmer
Mar 19, 2004
147
EU
Hello all.

Please how can i Send a form variables when a website load automaticaly?

Thanks you
 
I'm sorry, but your question is not clear to me.
Send -what?
-where?
-when?
-how?
 
Ok. I'm sorry.

I making a script which has a form that calls itself on submit the username and password.

when the page is loads again itself, I have a username and password, right?, well this username and password I need to pass to other page automatically.

Because in my other page I have the auth script

Thanks you
 
All right, now we can say something meaningful.
I would check in the PHP code upon submittal if there are values for username and password. If that is so, I'd include the auth script right in the page and evaluate there. No need to call another page.
Code:
<?php
if ($_POST['username'] && $_POST['password']){
   # include the auth script
   include('./auth.php');
}
Makes sense?
 
You can do like this:
Code:
session_start();

if (!($_SESSION['user_id'])) { 
  /* if no session, show login form */

  if ($_POST['username'] && $_POST['password']){
     /* include the auth script */
     [b]require[/b]('auth.php');
  } /* end if ($_POST['username'] && $_POST['password']) */
} /* end if (!($_session['user_id'])) */
else { /* already logged in */
  echo "You are logged in, <b>{$_SESSION['user_name']}</b>.<br />";
} /* end else: already logged in*/
/* here you can add logout function:
  if ($submit = "Logout") {... */

Then, in the required script "auth.php", you need to run a query on your database or however you gather your login information.

You can then do something like:

Code:
/* we assume you already queried 
database for password and username */

if (mysql_num_rows($row) > 0) {
  /* This means login is a-ok. */
  $_SESSION['user_id'] = $row['user_id'];
  $_SESSION['user_name'] = $row['user_name'];
}

ps. code not tested, so might be buggy!
Dont consider this as "final code"; but use for inspiration only! You should also crypt your passwords with salt.

look up crypt or md5, etc. on php.net

Olav Alexander Mjelde
Admin & Webmaster
 
btw. you might want to add your login form:

Code:
session_start();

if (!($_SESSION['user_id'])) { 
  /* if no session, show login form */

  if ($_POST['username'] && $_POST['password']){
     /* include the auth script */
     require('auth.php');
  } /* end if ($_POST['username'] && $_POST['password']) */
  else {
    /*Show login form */
    require("login_form.php");
  }
} /* end if (!($_session['user_id'])) */
else { /* already logged in */
  echo "You are logged in, <b>{$_SESSION['user_name']}</b>.<br />";
} /* end else: already logged in*/
/* here you can add logout function:
  if ($submit = "Logout") {... */


Olav Alexander Mjelde
Admin & Webmaster
 
Thanks you very much... let me try it and I will let you know.

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top