I'm trying to implement code into a perl-based download script in order to check if a visitor to a download url has logged into WordPress. Otherwise do not allow the download. The direct download links are like external.com/vembed- on the perl script end .

I'm trying to add the code in 1 and 2 below into 3:


define('COOKIE_DOMAIN', '.xxxfff.com'); 
define('COOKIEHASH', md5('xxxfff.com')); 

define('ADMIN_COOKIE_PATH', '/');
define('COOKIEPATH', '/');
define('SITECOOKIEPATH', '/');


require_once $_SERVER['DOCUMENT_ROOT'] . 'blog/wp-load.php'; 
global $current_user;
$current_user = wp_get_current_user();

if ( !function_exists( 'is_user_logged_in' ) ) { 
    require_once    $_SERVER['DOCUMENT_ROOT'] . 'blog/wp-includes/pluggable.php'; 

$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
    // Not logged in.
    echo 'not logged in';
} else {
    // Logged in.
    echo 'logged in';

(part of the download script code)

I tried and expected to be able to check whether the user is logged in to WordPress but nothing happened.

What can I do on the WordPress end and the perl script end?

  • 1
    You'd need to have a copy of the browsers cookie, that's how it determines if you're logged in, but that's not feasible for what you're doing if it's done from a clientside perl script. If this is server side, you would need to pass any cookies the browser sent along with your request. I'd also strongly advise against putting a dedicated PHP file that bootstraps core from scratch for security reasons. There's no reason it couldn't be done in a page template, a hook, or a REST API endpoint – Tom J Nowell May 16 '19 at 16:20

Your Answer

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

Browse other questions tagged or ask your own question.