0

I basically want to know it if is possible to create a system where either when a user wants to download something it creates a temporary download page (not a download link, this I want static - I hotlink files instead of upload them directly on my server) and the page will delete itself after a certain period of time. Or my other solution may be to restrict the visibility of a page or pages content based on the url of how the user got there. The reason I ask is because I use adf.ly for guests to download things and members don't get the adf.ly pages, they go straight to the download. The registered user download page is blocked from guests accessing it but if any guest shares the guest download link's page url after the adf.ly, anyone can bypass the adf.ly and go straight to the download page via the direct link. Is there a way to make the page boot them off if they didn't get to the page via the adf.ly link or somehow create a temporary download page that will only stay up a couple of minutes and then disappear and keep changing the url so people can't give out the direct guest download link? If there is any way to do this I would be grateful :)

0

For your first question "Detect where they are coming from", Just check the $_SERVER['HTTP_REFERER'] for your expected web address.

For the second "Create a short lived page", your answer lies in the set_transient() method. You can do something like:

function create_page() {
    if ( get_current_user_id() )
        return "<html>...</html>";
    return false;
}
function get_page( $unique_id ) {
    // Get an earlier created page if it's still alive
    $page = get_transient( $unique_id );
    if ( !$page ) {
        // Try creating a new page
        $page = create_page();
        if ( !$page )
            return false;
        // Cache the page and allow it to live for 1 hour
        set_transient( $unique_id, $page, HOUR_IN_SECONDS );
    }
    // Return the page
    return $page;
}

Please note the code sample will require modifying to your needs. Basically it creates a page or an inset for a page and saves it to the database with a lifetime of 1 hour. You could accompany this by adding the $unique_id to the users metadata. That way you can be sure only a single user can access the page within it's lifetime.

  • Bear in mind that $_SERVER['HTTP_REFERER'] is unreliable -- it can be spoofed, and not all browsers send it. – Pat J Sep 25 '13 at 21:03
  • Well I am using a plugin to run php code in a post or page and I had an old code that worked for checking the referer and sending them there (adfly) if they didnt come from it but now it is not working giving an error "Warning: Cannot modify header information - headers already sent by (output started at /home4/fmph12/public_html/wp-content/themes/twentythirteen/header.php:13)" and the code I was using was <?php if($_SERVER["HTTP_REFERER"] === "adf.ly/WStsb") { // go to download page } else { header("Location: adf.ly/WStsb"); } ?> anyone have any idea why it wouldnt work now – Ryan Joseph Kita Sep 29 '13 at 3:08
  • @RyanJosephKita That error means that data has already been sent to the browser, meaning it's too late to set the headers. – Twifty Sep 29 '13 at 5:16
  • but the odd thing is, that it worked for me previously. but then my wordpress site started messing up and displaying the wrong post content despite the url being for the page needed. like example.com/blahblah/blahhhh - The blahhhh child page would show the content of its parent instead "blahblah" and i couldnt correct it even disabling all plugins. So i re-did a fresh thing of wordpress and now the php code isnt working anymore despite it working before the fresh install. – Ryan Joseph Kita Sep 29 '13 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.