You have to check the site from wich your user is came from.
This site you can get with the JavaScript "refferer". It exist a mothod in php like this but i can released only in javascript.
Code:
<script type="text/javascript">
var lastpage = document.referrer;
<script type="text/javascript">
Afterwards you have to check "was the last page like yours?"
You have to take "if and else" to check this.
PHP Code:
<script type="text/javascript">
var lastpage = document.referrer;
if (lastpage == "yourSiteAsAString") {
<?php
mysql_query("UPDATE account.account SET `coins` = `coins` + 50 WHERE `id`='".mysql_real_escape_string($_SESSION['user_id'])."'") or die (mysql_error());
?>
var result = "you earned coins";
}
else {
var result = "access denied";
}
<script type="text/javascript">
With document.refferer you'll get the last page in most of the cases.
But sometimes you get an empty string.