Jump to content

Special restriction of some sort?


Gldnbr

Recommended Posts

How do I make it so if I get the question right, I have access to view the next page?

For example, if I get this question right in index-1.php correct, it would take me to index-2.php (like in the script below),

but if you don't get the question correct in index-1.php, you cannot have access/view index-2.php.

 

Why I need this?  Well, if you change the URL http://--------/index-1.php to http://--------/index-2.php, you can easily go from index-1.php to index-2.php without having to answer the question correctly.

 

index-1.php:

<?php
if(isset($_POST['submit'])){

$number = $_POST['number'];
if ($number == "elephant"){
header("Location: http://localhost/index-2.php");
exit();}
}
?> 

<html>
<head>
  <title>PHP Test</title>
</head>
<b>LEVEL 1</b>
<body>
<p>
<font face="Courier New">c291cmNl</font>
</p>
<br/></body>
</html>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  Answer: <!-- "elephant" --> <input type="text" name="number" /><br />
</select>
<input name="submit" type="submit">
</form>

 

Thanks

Link to comment
Share on other sites

Edit: Oops, I'm too slow. :P

 

Use sessions to keep track of where the user is at. If they haven't answered the question right, send them back to the previous question.

<?php
session_start();
if(isset($_POST['submit'])){

$number = $_POST['number'];
if ($number == "elephant"){
$_SESSION['question'] = 2;
header("Location: http://localhost/index-2.php");
exit();}
}
?>

 

Then on index-2:

<?php
session_start();

if (!isset($_SESSION['question']) OR $_SESSION['question'] != 2){
   header("Location: http://localhost/index-1.php");
}

?>

Link to comment
Share on other sites

Okay I see that now.

 

This time I am trying to do the same for index-2.php to index-3.php, anyone know what is up?

 

ERROR:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\index-2.php:10) in C:\xampp\htdocs\index-2.php on line 17

 

index-2.php:

<?php
session_start();

if (!isset($_SESSION['question']) OR $_SESSION['question'] != 2){
   header("Location: http://localhost/index-1.php");
}

?>

<?php
session_start();
if(isset($_POST['submit'])){

$number = $_POST['number'];
if ($number == "oil vial"){
$_SESSION['question'] = 3;
header("Location: http://localhost/index-3.php");
exit();}
}
?> 

<html>
<head>
  <title>PHP Test</title>
</head>
<b>LEVEL 2</b>
<body>
<p>
<font face="Courier New">vhwisgtpulffjroixfztpilnlixhjkmllwprkrmxyagrtonrcimeopytyioavbvykivnyqgxvzibjxwjzvmkdbhpwlbofudzpmys</font>
</p>
<br/></body>
</html>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  Answer: <input type="text" name="number" /><br />
</select>
<input name="submit" type="submit">
</form>

 

index-3.php:

<?php
session_start();

if (!isset($_SESSION['question']) OR $_SESSION['question'] != 3){
   header("Location: http://localhost/index-2.php");
}

?>

<?php
session_start();
if(isset($_POST['submit'])){

$number = $_POST['number'];
if ($number == "red hot chili peppers"){
$_SESSION['question'] = 4;
header("Location: http://localhost/index-4.php");
exit();}
}
?> 

<html>
<head>
  <title>PHP Test</title>
</head>
<b>LEVEL 3</b>
<body>
<p>
<font face="Courier New">cmVkIGhvdCBjaGlsaSBwZXBwZXJz</font>
</p>
<br/></body>
</html>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  Answer: <input type="text" name="number" /><br />
</select>
<input name="submit" type="submit">
</form>

Link to comment
Share on other sites

output started at C:\xampp\htdocs\index-2.php:10 (line 10)

 

You are sending output to the browser at line 10 in your file.

 

I'll guess it is the blank line inbetween your ?> and <?php tags -

?>
                   <----------- this is a line that is outside of your php code and will be sent to the browser.
<?php

 

You also need an exit; statement after your header() redirect, because anyone who wanted to view your page can just ignore the header() redirect that is being sent to the browser.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.