|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I am new to PHP and to email lists so I apologize in advance.
What I am trying to do is to take a password from user input, check it to make sure it is == to something, say “burgers” My problem is, I do not know how to make the Else statement... How do I get it to open a new url? I want it IF yes open this page, else open this page or If it is not correct then Say the password is incorrect or something… Else Open a different webpage My last attempt: --------------- <BODY onLoad="top.window.focus()"> <?php // Define your password $password = "burgers"; if ($_POST['pw'] != $password) { ?> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> <TR> <TD ROWSPAN=2 WIDTH=50%> <img src="images/charlee.gif"> </TD> <TD WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE> <FONT FACE="ARIAL" SIZE=2><B>You'll need a password to get in here. We're tryin' to keep out the riff-raff.</B></FONT><BR> </TD> </TR> <TR> <TD WIDTH=50% ALIGN=CENTER VALIGN=BOTTOM> <CENTER> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <br /> Name: <input type="text" name="Name" /> <br /> Email: <input type="text name="email" /> <br /> What is the Current Coupon Password?: <input type="text" name="pw" /> <input type="submit" value="Get Coupon!"/> </form> <A HREF="index.html" TARGET="_blank"><B>Return to Char-lees</B></A></FONT> </CENTER> </TD> </TR> </TABLE> <?php } else{ $file = fopen("http://www.google.com/","r"; ?> <?php } ?> --------------- This creates a nice small form with an image to the left. My problem is, I do not know how to make the Else statement... How do I get it to open a new url? I want it IF yes open this page, else open this page Andrew Prostko AProstko @ verizon.net |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Andrew Prostko wrote:
> I am new to PHP and to email lists so I apologize in advance. > > > What I am trying to do is to take a password from user input, check > it to make sure it is == to something, say “burgers” > > My problem is, I do not know how to make the Else statement... > How do I get it to open a new url? > I want it IF yes open this page, else open this page > or > If it is not correct then Say the password is incorrect or > something… > Else > Open a different webpage > > My last attempt: > --------------- > <BODY onLoad="top.window.focus()"> > > <?php > > // Define your password > $password = "burgers"; > > if ($_POST['pw'] != $password) { > > ?> > <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> > > <TR> > <TD ROWSPAN=2 WIDTH=50%> > > <img src="images/charlee.gif"> > </TD> > <TD WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE> > <FONT FACE="ARIAL" SIZE=2><B>You'll need a password to get in here. We're > tryin' to keep out the > > riff-raff.</B></FONT><BR> > </TD> > </TR> > <TR> > <TD WIDTH=50% ALIGN=CENTER VALIGN=BOTTOM> > <CENTER> > <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> > <br /> > Name: <input type="text" name="Name" /> > <br /> > Email: <input type="text name="email" /> > <br /> > What is the Current Coupon Password?: <input type="text" name="pw" /> > <input type="submit" value="Get Coupon!"/> > </form> > <A HREF="index.html" TARGET="_blank"><B>Return to Char-lees</B></A></FONT> > </CENTER> > </TD> > </TR> > </TABLE> > > <?php > } > else{ > > $file = fopen("http://www.google.com/","r"; > > ?> > > <?php > } ?> > --------------- > > This creates a nice small form with an image to the left. > > My problem is, I do not know how to make the Else statement... > How do I get it to open a new url? > I want it IF yes open this page, else open this page > > Andrew Prostko > AProstko @ verizon.net > > You might be in need of the header() function in php -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Wednesday 19 September 2007 15:50:08 Andrew Prostko wrote:
> My problem is, I do not know how to make the Else statement... > How do I get it to open a new url? > I want it IF yes open this page, else open this page Andrew, try the header() function: <?php if ($_POST['pw'] != $password) { ?> ...show your form... <?php } else { header ("otherpage.php"); } One problem you might be having is that the < body > tag at the very top might be sending headers to your browser before your else statement has a chance to kick in, generating an error which reads something like, "Headers already sent..." Try moving it to after the conditional, like this: <?php if ($_POST['pw'] != $password) { ?> < BODY onLoad="top.window.focus()" > ...rest of your form... <?php } else { ...and so on. -- Richard S. Crawford Editor-in-chief, Daikaijuzine (http://www.daikaijuzine.com) Personal website: http://www.mossroot.com http://www.myspace.com/underpope / underpope.livejournal.com "We are here to each other get through this thing, whatever it is." (Kurt Vonnegut, 1922 - 2007) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBG8bwj0Q4njIwYM+oRAnx7AJ9Mdo/5qjv+GfAhZQEaQAEmmw46ywCfQ/g+ DIMmu/4IGtcWWZEU97Y7o0E= =RGOr -----END PGP SIGNATURE----- |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Ok, so I started using the header code that was suggested: And I get this error: Parse error: parse error, unexpected '{' in /home/char-lee/public_html/beta/1.php on line 3 This is the code: ----------- <?php if ($_POST['pw'] != burgers { header("Location: password.php"); } else { header("Location: sept-coupon07.html"); } ?> ----------- |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Thu, 20 Sep 2007 02:52:19 -0400 Andrew Prostko said:
Ok, so I started using the header code that was suggested: And I get this error: Parse error: parse error, unexpected '{' in /home/char-lee/public_html/beta/1.php on line 3 This is the code: ----------- <?php if ($_POST['pw'] != burgers { header("Location: password.php"); } else { header("Location: sept-coupon07.html"); } ?> ----------- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Close your parenthesis, daggummit! if ($_POST['pw'] != burgers ) ^^^ -- Don Read dread@aceweb.com -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Andrew Prostko wrote:
> Ok, so I started using the header code that was suggested: > > And I get this error: > > Parse error: parse error, unexpected '{' in > /home/char-lee/public_html/beta/1.php on line 3 > > This is the code: > ----------- > <?php > if ($_POST['pw'] != burgers You'll be wanting to put burgers in quotes and close the bracket on the line above. if ($_POST['pw'] != 'burgers') > { > header("Location: password.php"); > } > else > { > header("Location: sept-coupon07.html"); > } > ?> > ----------- I suggest you find a beginners book or Google for a beginners tutorial on PHP because it would appear you need to learn some fundamentals of the language before continuing. -Stut -- http://stut.net/ |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Wow, it really must be late, Thank you for pointing out that missing parenthesis .... 330am and now I can go to bed happy... TY VM Ending Code for anyone listening: Get PW from another .php page using: <form action="passwordcheck.php" method="post"> <br /> What is the Password?: <input type="text" name="pw" /> <input type="submit" value="Submit!"/> </form> This is the passwordcheck.php code: <?php if ($_POST['pw'] != burgers) { header("Location: password.php"); } else { header("Location: sept-coupon07.html"); } ?> |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Andrew Prostko wrote:
> Wow, it really must be late, Thank you for pointing out that missing > parenthesis > ... 330am and now I can go to bed happy... TY VM > > Ending Code for anyone listening: > > Get PW from another .php page using: > > <form action="passwordcheck.php" method="post"> > <br /> > What is the Password?: <input type="text" name="pw" /> > <input type="submit" value="Submit!"/> > </form> > > This is the passwordcheck.php code: > <?php > if ($_POST['pw'] != burgers) You might want to quote that as well: 'burgers' otherwise php will look for a defined value called 'burgers', ie: php will look for this: define('burgers', 'xyz'); and try to compare against that (in this case the real password is 'xyz'). If you turn up error reporting: error_reporting(E_ALL); and display errors: ini_set('display_errors', true); you would see a message about this. -- Postgresql & php tutorials http://www.designmagick.com/ |
|
![]() |
| Outils de la discussion | |
|
|