Page 1 of 2

[SOLVED]Help

Posted: Sun Jun 06, 2004 12:53 pm
by bawla
I havent been doing php in a while now and I'm afraid I forgot some of it. I'm trying to make a simple log in script, this is what I have so far, I just need to know how could I get it to go to a certain page after someone fills the form out and it is correct.

Code: Select all

<?php

$password = "bnx4life";

if ($_POST['txtPassword'] != $password) {

?>

<b>Log In</b>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>

<p><input type="submit" name="Submit" value="Login" /></p>

</form>

<?php

}
else {

?>

<p>BnX members please log in.</p>

<?php

}

?>

Posted: Sun Jun 06, 2004 12:55 pm
by Deemo
header()

you can use header("Location: page.php"); to go to whatever page you want

Posted: Sun Jun 06, 2004 1:01 pm
by tim
seems like your else command would say that the log-in data is correct

you may use Javascript to reload to a certain page

you may use php as well, header()

seeing you have html output before the else {, you would have to use output buffering (ob_start()) to cut in n out or use the javascript (would I would do)

<script language=javascript>location.replace('page.php')</script>

Posted: Sun Jun 06, 2004 1:05 pm
by bawla
How would that look like?

Posted: Sun Jun 06, 2004 1:06 pm
by tim
how would what look like?

:?: :roll:

Posted: Sun Jun 06, 2004 1:07 pm
by bawla
The whole code.

Posted: Sun Jun 06, 2004 1:09 pm
by patrikG
have a look at the examples for [php_man]header[/php_man] in the PHP-manual.

Posted: Sun Jun 06, 2004 1:09 pm
by tim
lol

just insert the header/javascript code provided anywhere.

the only catch with headers is you cannot have any output (html tags) before it. The solution(s):

use the javascript

use output buffering

research the ob_start() if you want to use headers, we are not going to write code for you.

Posted: Sun Jun 06, 2004 1:14 pm
by bawla
Well when I use the header or the javascript, the page loads before you fill out the form.

Posted: Sun Jun 06, 2004 1:16 pm
by tim
well it would have to go in your else statement

:?

Posted: Sun Jun 06, 2004 1:18 pm
by bawla
Nope doesnt work.

Posted: Sun Jun 06, 2004 1:19 pm
by John Cartwright
YES IT DOES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Sun Jun 06, 2004 1:19 pm
by tim
post your entire code.

Posted: Sun Jun 06, 2004 1:21 pm
by bawla

Code: Select all

<?php

$password = "bnx4life";

if ($_POST['txtPassword'] != $password) {


?>

<b>Log In</b>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>

<p><input type="submit" name="Submit" value="Login" /></p>

</form>

<?php

}
else {

header("Location: home.html");


?>

<p>BnX members please log in.</p>

<?php

}
?>

Posted: Sun Jun 06, 2004 1:23 pm
by bawla
Just to let you know before you start yelling at me, yes I did forgot some of what I knew before, but I started out with very little from the beginging.