PDA

View Full Version : PHP Code.


Aasixx
08-29-2012, 06:36 PM
Well, I'm using Derpstra's wonderful PHP code (thank you for posting it, Derpstra!) and I was wondering if there was a way to make it where you cannot refresh that page or go back. I'm using this page for when they purchase a certain amount of cash for real money that they're sent to this page to automatically gain their purchased cash. But, I noticed, when you refresh/press go back, they can easily cheat and gain a lot of cash for free. I want to make it where they cannot cheat. Is this possible?

Code:
<?php

include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("functions/functions_friends.php");
include("functions/functions_items.php");
include("inc/lang.php");
include("inc/bbcode.php");

//***************//
// START SCRIPT //
//***************//

$cashname = grabanysetting("cost");
$reward= 1;

if($isloggedin == "yes"){
changecash($reward, $GLOBALS['username'], $GLOBALS['money']);
$article_title = "Hello, {$username}!";
$article_content = "You have gained {$reward} {$cashname}.";
}
else{
$article_title = "You are not logged in!";
$article_content = "You must be logged in to view this page!";
}

//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);
?>

Hall of Famer
08-30-2012, 04:52 AM
You can use PHP sessions to achieve this. It displays a message saying 'Session Expired' if they click the back or forward button on a page they have already visited.

First of all, you need to define the session var in the purchase page, it should look like this below:


// In your cash purchase page.
$_SESSION['reward'] = 1;


Then unset the session in the money acquisition page:

// In your actual money reward page
if($isloggedin == "yes" and isset($_SESSION['reward'])){
changecash($reward, $GLOBALS['username'], $GLOBALS['money']);
$article_title = "Hello, {$username}!";
$article_content = "You have gained {$reward} {$cashname}.";
unset($_SESSION['reward']);
}
elseif($isloggedin == "yes" and empty($_SESSION['reward'])){
$article_title = "An error has occurred";
$article_content = "The last session has expired, please return to the previous page.";
}
else{
$article_title = "You are not logged in!";
$article_content = "You must be logged in to view this page!";
}

Aasixx
09-17-2012, 05:15 PM
Awesome, thanks again HoF!