Title: phpwpuser's Replies | WordPress.org

---

# phpwpuser

  [  ](https://wordpress.org/support/users/phpwpuser/)

 *   [Profile](https://wordpress.org/support/users/phpwpuser/)
 *   [Topics Started](https://wordpress.org/support/users/phpwpuser/topics/)
 *   [Replies Created](https://wordpress.org/support/users/phpwpuser/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/phpwpuser/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/phpwpuser/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/phpwpuser/engagements/)
 *   [Favorites](https://wordpress.org/support/users/phpwpuser/favorites/)

 Search replies:

## Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)

 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Custom Script For PDF loading: Failed to load PDF document.](https://wordpress.org/support/topic/custom-script-for-pdf-loading-failed-to-load-pdf-document/)
 *  Thread Starter [phpwpuser](https://wordpress.org/support/users/phpwpuser/)
 * (@phpwpuser)
 * [4 years ago](https://wordpress.org/support/topic/custom-script-for-pdf-loading-failed-to-load-pdf-document/#post-15660807)
 * 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](https://wordpress.org/support/users/phpwpuser/).
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Custom Script For PDF loading: Failed to load PDF document.](https://wordpress.org/support/topic/custom-script-for-pdf-loading-failed-to-load-pdf-document/)
 *  Thread Starter [phpwpuser](https://wordpress.org/support/users/phpwpuser/)
 * (@phpwpuser)
 * [4 years ago](https://wordpress.org/support/topic/custom-script-for-pdf-loading-failed-to-load-pdf-document/#post-15660189)
 * 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](https://wordpress.org/support/users/phpwpuser/).

Viewing 2 replies - 1 through 2 (of 2 total)