is it 20 times per person per day or just 20 times per day?
is it 20 times per person per day or just 20 times per day?
all thanks to Jshor , yes it is working 20 click ( you can edit it to any number ) per IP per day
each IP must wait for next day in order to click more 20 clicks and so on
we just waitting for Jshor to give us a comment how to make the link dynamic as i've said, however i'm not sure how to run a php command inside a javascript .
Alright, then, but I'm not clear on whatyou mean by "it doesn't work". Is it giving you a Jscript error, not opening the window, or the script fails altogether?
Depending on the problem will determine the solution for it.
If it's a Jscript error, magic quotes should fix it [that's waht I think is most likely].
- Josh
egturnkey (07-31-2009)
It is working correct , but as you can see here
at the index.php
where should i put the link of the file which will be downloading upon clicking on the link which we limited its number of clicks per ip per dayCode:var myLinkURL = "http://mysite.com/"; // change the link
as it clear , it is a javascript and hence i can only add a direct link
so what if i want to add a dynmic link ( php ) like the following
which will call the file that will be downloadedCode:".FILE_DOWNLOAD."?productID=".$productrow['productID']."
the was the original code
( if logged then download , if not then " Members Only " , if not both then the product not avl )
i've replaced the 1st part ( if logged ) with the code that limited the number of downloads which you've given to me ( all thanks to you ) but as i've told you , the problem will be in the link itself
Code:<? if ($productrow['status']) { if ($productrow['type'] == 0 && ($isMember || $isAdmin)) { echo "<a href='#' onclick='append_cookie(\"cartcontent\", \"".$productrow['productID']."\", \"\")'>"; echo "<img src='$addtocart_button' border=0>"; echo "</a>"; echo "<a href='".FILE_DOWNLOAD."?productID=".$productrow['productID']."'>"; echo "<img src='$download_button' border=0>"; echo "</a>"; } else if ($productrow['type'] == 0 && (!$isMember && !$isAdmin)) { echo "<b>Member Download Only</b>"; } } else { // product n/a for download or purchase echo "<img src='$na_button' border=0>"; } ?>
so how can we change the fixed link in javascript code
to that one in blue colorCode:var myLinkURL = "http://mysite.com/"; // change the link
thanks
thanks so much,
it has been solved and i've edit the following
to the followingCode:var myLinkURL = "http://mysite.com/"; // change the link
Code:var myLinkURL = "<?php echo "".FILE_DOWNLOAD."?productID=".$productrow['productID'].""; ?>"; // change the link
Now it works perfect
thanks so much jshor for your help, it is done![]()
Alright, I gotcha. The window.open function can be disabled if the if..else statement determines that the user doesn't have access to the link. This code should do the trick:
[Revised] index.php:
HTHPHP Code:<?php
include('config.php'); // connect to db
$ip = $_SERVER[REMOTE_ADDR];
$date = date("Y-m-d"); // mysql db format as requested.
$qq = mysql_query("SELECT * FROM ip_table WHERE ip='$ip' AND timestamp='$date'") or die(mysql_error()); //select query
if(mysql_num_rows( $qq ) > 0) {
$int = mysql_num_rows( $qq ) or die(mysql_error()); // number of times clicked by user today
} else {
$int = 0;
}
if ($productrow['status']) {
if ($productrow['type'] == 0 && ($isMember || $isAdmin)) {
$dlLink = FILE_DOWNLOAD."?productID=".$productrow['productID'];
}
}
?>
<html>
<head>
<script type="text/javascript">
var myLinkURL = "<?php echo $dlLink; ?>";
var timesToClick = 20; //times you wanna click the link before obj becomes disabled.
// NO NEED TO EDIT BELOW THIS //
var exp = parseInt(<?php echo $int; ?>); // number of times clicked [when page loaded] + 1more click..
var http_request = false;
function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.open('POST', url + parameters, true);
http_request.send(null);
determineClickedTimes(); //function to call clicked times constraint
}
function determineClickedTimes() {
exp = parseInt(exp + 1);
if(exp > parseInt(timesToClick - 1)) { //if obj is clicked {x} times
document.getElementById('aClick').disabled = "disabled"; //disable the link
document.getElementById('imgClick').disabled = "disabled"; //disable the image
} else {
if(myLinkURL == '') {
location.href = myLinkURL;
} else {
return false;
}
}
}
</script>
</head>
<body>
<?php $ip = $_SERVER[REMOTE_ADDR]; ?>
<br /> <br /> Link:
<a href="javascript:makeRequest('req.php', '?IP=<?php echo $ip; ?>');" id="clicker">Click here</a>
<?
if ($productrow['status']) {
if ($productrow['type'] == 0 && ($isMember || $isAdmin)) {
echo "<a href='#' onclick='append_cookie(\"cartcontent\", \"".$productrow['productID']."\", \"\")'>";
echo "<img src='$addtocart_button' border=0>";
echo "</a>";
echo "<a href=\"javascript:makeRequest('req.php', '?IP=<?php echo $ip; ?>');\" id=\"aClick\">";
echo "<img src='$download_button' border=0 id=imgClick>";
echo "</a>";
}
else if ($productrow['type'] == 0 && (!$isMember && !$isAdmin)) {
echo "<b>Member Download Only</b>";
}
} else { // product n/a for download or purchase
echo "<img src='$na_button' border=0>";
}
?>
</body>
</html>![]()
- Josh
Bookmarks