Jump to content

Prevent random navigation in PHP


kid_drew

Recommended Posts

Hey guys,

I'm trying to code up a simple game where the user passes from one page to the next through a series of links.  How can I prevent a user from cheating by typing in the URL of a page that is not in the logical flow of the game?  Some kind of cookie trick, I'm sure, but I can't seem to wrap my head around it.

 

-Drew

Link to comment
Share on other sites

a session containing the page number

 

so... if the person is on page 2 it would look like this:

http://mysite.com/mypage.php?page=2

 

<?php
if($_SESSION['page'] < $_GET['page']){
    header('Location: /mypage.php?page='.$_SESSION['page']);
    exit;
}else{
    //display the page
}
?>

 

then when they advance, you need to incrament the session page number by 1

<?php
$_SESSION['page']++;
?>

Link to comment
Share on other sites

Basically what redarrow means is, use sessions. :-)

 

<?php

  session_start();

    if($_SESSION['step'] != $_GET['page']) {
      header("location: index.php?page=".$_SESSION['step']."");exit;
    }

      else 
      {
        $_SESSION['step']++;
      }

?>

 

But the approach and code depends on how you're moving them from page to page (Or step...wtvr)

 

Edit: Wow...typo :-P

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.