Help coding php to detect and release download after a count down

So heres the deal i want to use the javascript from adblockdetector.com to detect is anyone downloading files from my site has an adblocker.
The only way i can figure out how to make everything work for the most part is by using iframe.

Im using gravity forms with wordpress to upload the files using a custom field.

this lets the file linked in the custom field to be a downloadable link <?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo '

Download Now!

'; } ?>
I chose to use <?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo ''; } ?>

once the iframe has been setup it either blocks the content from being downloaded or shows a download link after a timer.

for the download link in the iframe when i try to call for

<?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo '

Download Now!

'; } ?>

the iframe tries to load a invalid page and not the file in the custom field.

you can see what im working with on my site gfuzz.net/?p=110

if there is a way i can combine all the code without using iframe that would be awesome.

here are the files im using to make all of this work.

<?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo ''; } ?> calls to
>
This script is whats detects if an adblock program is running then loads the code.html page once the adblock has been disabled
code.html calls for a timer

Your code will be ready soon

Thank you for choosing gFuzz

after 20 seconds has past the timer loads dl.php
thats where the <?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo '

Download Now!

'; } ?>

was put

the only issue i have is when i try to echo the file. it just tries to load a page
as
‘.$customField[0].’.html

i dont want this link to open a page i want it to link to the file i have in the custom field of the parent page.

I tried to explain my situation as best i can if anyone can give me some pointers that would be great thank you.

Well, not sure about all that code, but, you forgot a big point! An iFrame is a NEW PAGE… If you set a value in one page and then call or load another, the variables in the first page do not exist in the loaded subpage. At least that is what I thought happens. So, you can still do it your way, but, you need to use session variables for anything you want to pass to the iFrame. Or, use Javascript to access hidden fields in the iFrame and load the custom field that way. (More tricky) Try passing the custom fields by session variables and see if that works.

so with this code

<?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo ''; } ?>
i can change it to

?php
session_start();
$_SESSION[’$customField[0]’] = $_GET[’$customField[0]’];
$ID = session_id();

$customField = get_post_custom_values(“file_attachment”);
if (isset($customField[0])) {
echo ‘’;
} ?>

so it main page>iframe>iframe
can the session but used for the final link to display the link of the custom form

Im new at this and trying to get it on a fly.

im not sure how i should have the session setup.

to better explain how my site works. i have a upload form that uploads my files into a post. in the post i have a custom field thats titled file_attached and its value is a download link $customField is loading $customField[0] which refers to the custom field in that post

i was wondering if there is a way to consolidate everything the code below does not work but could there be a way of rewriting it to work

<?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo '

Your code will be ready soon

Thank you for choosing gFuzz

'); }

}
?>
var _abdDetectedFnc = ‘_enabled’;
var _abdNotDetectedFnc = ‘_disabled’;

where
timer.js contains

var Timer; var TotalSeconds;

function CreateTimer(TimerID, Time) {
Timer = document.getElementById(TimerID);
TotalSeconds = Time;

UpdateTimer()
window.setTimeout("Tick()", 1000);

}

function Tick() {
if (TotalSeconds <= 0) {
document.write(Download Now!);

   return;
}

TotalSeconds -= 1;
UpdateTimer()
window.setTimeout("Tick()", 1000);

}

function UpdateTimer() {
Timer.innerHTML = TotalSeconds;
}

Well, I wrote a few paragraphs and then realized what you actually want…

You just want to display a link and have it be a button not a link. I get it… Finally understand!

Your quote:

the only issue i have is when i try to echo the file. it just tries to load a page as '.$customField[0].'.html

i dont want this link to open a page i want it to link to the file i have in the custom field of the parent page.


Okay, you have an HREF in that comment. So, a HREF can send the user to another page or to anywhere you wish. You want to do this so the actual file’s address is not on the page to be read by robots or web spiders.

One simple way would be to not use the iFrame, but, just hide the page in a field. You could do something like this:
echo ’ Not shown, but will have page in it.
echo ‘

Download Now!

’;
Same as before but no src page and added Javascript function call…
Then, have a small Javascript function to call the page…

What this will do is allow you to use PHP to create the $customField[0] and save it in the hidden field as data.
Then, when the link is pressed, it does not have a HREF value, but, calls the Javascript which goes to the page.
Is that what you want? Still not sure what you need to do this for… you mentioned “adblockers” but,
you also are talking about page links… ?? Hope that is what you are looking for…

Basically thats how i want it.

before it displays the download link i want 2 things to happen.

The first thing be for the php to call on the adblock javascript.

Once all of the requirements are met

i want a count down timer that releases

the download button.

basically the method i want to try uses 2 .js files
and some other script to give the .js files meaning.

i want the php to look at

i have this

If function _disabled() {

is true this js will trigger another js function

i want the timer to be displayed

once the timer hits 0 i want it to display

an href or something similar to show a link for what ever is contained in .$customField[0].’

in the template page so when ever i want to add another file i dont have to do any laborious coding


.$customField[0].’ is referring to a field called file_attachment. The fields value ie. the link to the file will always be different per post

every thing works fine if i just add

<?php $customField = get_post_custom_values("file_attachment"); if (isset($customField[0])) { echo '

Download Now!

'; } ?>

i somehow want it to run the js test
if the test is failed nothing will show except a notice saying what to do for them to pass.

I appreciate your help.

Im more thinking its about calling php functions using javascript

Well, I found it is quite easy to use Javascript to hide and show DIV’s.
You can also load these DIV’s with a called PHP file using Jquery/Ajax whatever it’s called these days… LOL
So, here is a nice link to show you how to hide and show a DIV.

Why start with that? You can “HIDE” the empty “download-now” display in a DIV with this code.
Then, when the adblocker stuff says go for it, you can load the real “download-now” display by loading the PHP file into the second DIV and then “SHOW” or “UNHIDE” it and there you go, it appears… Nice effect too!

So, here’s that part…
http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/

you know this just worked for me.

i used a redirecting countdown timer as the trigger for the first toggle div

once the timer hits 0 it would try and redirect to a url in this case i used the toggles url switch hiding the div tag with the download

Here is the toggle i used

<script language="javascript"> 
function toggle() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("displayText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		
  	}
	else {
		ele.style.display = "block";
		
	}
} 
</script>
 
<a id="displayText" href="javascript:toggle();"></a>
<div id="toggleText" style="display: none"><?php
echo '<h3><a href="'.$customField[0].'" class="button"><img src="button_1.png"></a></h3>';
?></div>

I used 2 different timers

[code]This is the redirecting timer i used

that out puts the time to this span

[/code]

Only issue i had with this was once the timer hit 0 it kept counting down.
so i just made the text transparent

and just iframed the first timer i had that uses document.write .

im sure there another way for it but the method i used can make a new page for each file using the template

if you want to see my end result here it a link to a download page on my site gfuzz.net/?p=123

Major props to you man. For putting up with me. Plus Karma man \m/(-_-)\m/

Sponsor our Newsletter | Privacy Policy | Terms of Service