kid_drew Posted July 25, 2007 Share Posted July 25, 2007 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 https://forums.phpfreaks.com/topic/61743-prevent-random-navigation-in-php/ Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 <?php session_start(); $_SESSION['x']="not cheating"; ?> <?php session_start(); if($_SESSION['x']=="not cheating"){ // game }else{ echo" you cheat"; } ?> Link to comment https://forums.phpfreaks.com/topic/61743-prevent-random-navigation-in-php/#findComment-307382 Share on other sites More sharing options...
The Little Guy Posted July 25, 2007 Share Posted July 25, 2007 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 https://forums.phpfreaks.com/topic/61743-prevent-random-navigation-in-php/#findComment-307383 Share on other sites More sharing options...
Caesar Posted July 25, 2007 Share Posted July 25, 2007 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 https://forums.phpfreaks.com/topic/61743-prevent-random-navigation-in-php/#findComment-307384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.