Title: Undefined index: SERVER_PORT when using wpcli
Last modified: September 19, 2017

---

# Undefined index: SERVER_PORT when using wpcli

 *  Resolved [Ioannis Kappas](https://wordpress.org/support/users/ikappas/)
 * (@ikappas)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/undefined-index-server_port-when-using-wpcli/)
 * When the plugin is activated and you try to use wpcli to issue commands, it throws
   exceptions of Undefined index: SERVER_PORT/SERVER_NAME in /classes/wp-security-
   utility.php:32
 * This happens because the $_SERVER[] environment variables are not available via
   cli. An additional check needs to be implemented like:
 *     ```
       if ( 'cli' === php_sapi_name() || defined('STDIN') ) {
               // This section of the code runs when WordPress is being runned from the terminal
               ...    
       } else {
               // This section of the code run when WordPress is being run from the browser
               ...
       }
       ```
   

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

 *  Plugin Contributor [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/undefined-index-server_port-when-using-wpcli/#post-9513860)
 * Thank you for reporting this. I have submitted a message to the plugin developers
   to investigate further your findings.
 * Kind regards
 *  Plugin Contributor [wpsolutions](https://wordpress.org/support/users/wpsolutions/)
 * (@wpsolutions)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/undefined-index-server_port-when-using-wpcli/#post-9519548)
 * Hi [@ikappas](https://wordpress.org/support/users/ikappas/),
    I think that the
   neatest way to handle this is to perhaps put a check at the beginning of the 
   get_current_page_url function along the lines of:
 *     ```
       if ( 'cli' === php_sapi_name() || defined('STDIN') ) {
               // return for cli case 
               return '';    
       }
       ```
   
 * Do you think the above will best solve your scenario?
 *  Thread Starter [Ioannis Kappas](https://wordpress.org/support/users/ikappas/)
 * (@ikappas)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/undefined-index-server_port-when-using-wpcli/#post-9520542)
 * Hi [@wpsolutions](https://wordpress.org/support/users/wpsolutions/)
 * I raised this issue mainly because I saw that wpcli was throwing errors with 
   this plugin activated. I don’t have a specific use case other than executing 
   wpcli commands successfully.
 * I don’t know whether this kind of check should be implemented at the `get_current_page_url`
   function or higher up in the call stack.
 * To better answer this question you probably need to decide on:
    Does this plugin
   need to load when running via CLI? If so does all of it need to load or only 
   some parts? Do you plan to support wpcli with custom commands? etc.
 * Hope this helps.
 *  Plugin Contributor [wpsolutions](https://wordpress.org/support/users/wpsolutions/)
 * (@wpsolutions)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/undefined-index-server_port-when-using-wpcli/#post-9530276)
 * Ok thanks for your feedback.
    I think for now I can see no pressing reason to
   support cli commands for this plugin since it is virtually always used via browser.
 * If in future cli support is needed, we can always revisit this and address this
   topic as needed.

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

The topic ‘Undefined index: SERVER_PORT when using wpcli’ is closed to new replies.

 * ![](https://ps.w.org/all-in-one-wp-security-and-firewall/assets/icon-256x256.
   png?rev=2798307)
 * [All-In-One Security (AIOS) – Security and Firewall](https://wordpress.org/plugins/all-in-one-wp-security-and-firewall/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/all-in-one-wp-security-and-firewall/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/all-in-one-wp-security-and-firewall/)
 * [Active Topics](https://wordpress.org/support/plugin/all-in-one-wp-security-and-firewall/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/all-in-one-wp-security-and-firewall/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/all-in-one-wp-security-and-firewall/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [wpsolutions](https://wordpress.org/support/users/wpsolutions/)
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/undefined-index-server_port-when-using-wpcli/#post-9530276)
 * Status: resolved