[SOLVED]Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

[SOLVED]Help

Post 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

}

?>
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

header()

you can use header("Location: page.php"); to go to whatever page you want
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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>
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

How would that look like?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

how would what look like?

:?: :roll:
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

The whole code.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

have a look at the examples for [php_man]header[/php_man] in the PHP-manual.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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.
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

Well when I use the header or the javascript, the page loads before you fill out the form.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

well it would have to go in your else statement

:?
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

Nope doesnt work.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

YES IT DOES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

post your entire code.
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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

}
?>
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post 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.
Post Reply