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
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 12:53 pm
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 » Sun Jun 06, 2004 12:55 pm
header()
you can use header("Location: page.php"); to go to whatever page you want
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 1:01 pm
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>
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:05 pm
How would that look like?
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 1:06 pm
how would what look like?
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:07 pm
The whole code.
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Sun Jun 06, 2004 1:09 pm
have a look at the examples for [php_man]header[/php_man] in the PHP-manual.
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 1:09 pm
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.
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:14 pm
Well when I use the header or the javascript, the page loads before you fill out the form.
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 1:16 pm
well it would have to go in your else statement
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:18 pm
Nope doesnt work.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Jun 06, 2004 1:19 pm
YES IT DOES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 1:19 pm
post your entire code.
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:21 pm
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
}
?>
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:23 pm
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.