Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter phpwpuser

    (@phpwpuser)

    I spent 2-3 days with this issue.
    I had to load external PHP. It was no problem. Problem was that external script doesn’t get SESSION from WordPress. Spending few days with this issue got me a very simple solution. In the beginning of the external (same domain, but not in WP structure) PHP file you need too add two things:
    1. Load wp-load.php file. That allows to work with WP settings and SESSIONS.
    2. Add template comment session if this file is inside the template directory. In the beginning below, comment is not full. You should use your comment section according to your template.

    Nobody helped me. But I will leave this solution if anybody needs it in the future.

    SOLUTION:

    <?php
    require_once(rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/wp-load.php');
    /**
     * The template for displaying all pages.
     *
    .....
    • This reply was modified 4 years ago by phpwpuser.
    Thread Starter phpwpuser

    (@phpwpuser)

    Ok. I made one more script:
    wp-content/templates/elegant/page-pdf-2.php

    @session_start();
    $name_file = $_SESSION['session_name'];
    if (mime_content_type($file) == 'application/pdf')
      {
    
        define('WP_USE_THEMES', false); // These lines I add only in WP script file
        status_header(200); // These lines I add only in WP script file
        // Header content type
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename="' . $name_file . '"');
        header('Content-Transfer-Encoding: binary');
        header('Accept-Ranges: bytes');
    
        // Read the file
        @readfile($file);
      }

    The problem is that I didn’t get the SESSION value when I am going directly yo the script: my-page-url-link.com/wp-content/templates/elegant/page-pdf-2.php

    • This reply was modified 4 years ago by phpwpuser.
Viewing 2 replies - 1 through 2 (of 2 total)