Title: Undefined variable when activating plugin in Localhost ( mamp server )
Last modified: November 9, 2017

---

# Undefined variable when activating plugin in Localhost ( mamp server )

 *  [davidguerreiro](https://wordpress.org/support/users/davidguerreiro/)
 * (@davidguerreiro)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/undefined-variable-when-activating-plugin-in-localhost-mamp-server/)
 * There is an error in plugin main file. You are relying on $_SERVER[‘REQUEST_SCHEME’]
   to check if it is a secure URL, which is wrong because $_SERVER[‘REQUEST_SCHEME’]
   might not exists. As such, there is an HTTP ERROR 500 when enabling the plugin
   in localhost servers ( I tested in mamp ).
 * To fix this, please replace this code :
 *     ```
       if( $_SERVER['REQUEST_SCHEME'] == "https" ){
       		define ( 'PTPDF_URL',  str_replace( "http://", "https://", WP_PLUGIN_URL . '/wp-advanced-pdf' ) );
       	} else {
       		define ( 'PTPDF_URL', WP_PLUGIN_URL . '/wp-advanced-pdf' );
        	}
       ```
   
 * by this ( optimize if required ) :
 *     ```
       if ( isset( $_SERVER['REQUEST_SCHEME'] ) )  {
       	if( $_SERVER['REQUEST_SCHEME'] == "https" ){
       		define ( 'PTPDF_URL',  str_replace( "http://", "https://", WP_PLUGIN_URL . '/wp-advanced-pdf' ) );
       	} else {
       		define ( 'PTPDF_URL', WP_PLUGIN_URL . '/wp-advanced-pdf' );
        	}
       } else {
       	if ( ( ! empty($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ) || $_SERVER['SERVER_PORT'] == 443 ) {
       		define ( 'PTPDF_URL',  str_replace( "http://", "https://", WP_PLUGIN_URL . '/wp-advanced-pdf' ) );
       	} else {
       		define ( 'PTPDF_URL', WP_PLUGIN_URL . '/wp-advanced-pdf' );
       	}
       }
       ```
   
 * Basically I am checking first if the variable $_SERVER[‘REQUEST_SCHEME’] is set
   and if not, it uses $_SERVER[‘HTTPS’] . In case it is empty then it checks if
   port 443 is being used ( this can be tricky, so I would recommend to optimize
   this code by plugin author ). Anyway using the code above it fixes the error 
   and makes the plugin work in localhost. Please fix it in the future releases.
   Thanks.
    -  This topic was modified 8 years, 7 months ago by [davidguerreiro](https://wordpress.org/support/users/davidguerreiro/).

The topic ‘Undefined variable when activating plugin in Localhost ( mamp server )’
is closed to new replies.

 * ![](https://ps.w.org/wp-advanced-pdf/assets/icon-256x256.png?rev=1384838)
 * [WP Advanced PDF](https://wordpress.org/plugins/wp-advanced-pdf/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-advanced-pdf/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-advanced-pdf/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-advanced-pdf/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-advanced-pdf/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-advanced-pdf/reviews/)

 * 0 replies
 * 0 participants
 * Last reply from: [davidguerreiro](https://wordpress.org/support/users/davidguerreiro/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/undefined-variable-when-activating-plugin-in-localhost-mamp-server/)
 * Status: not resolved