jason_15 Posted September 8, 2015 Share Posted September 8, 2015 I dont get expected output <?php function is_localhost(){ if(in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))){ return true; } return false; } function home_url(){ $scheme = $_SERVER['REQUEST_SCHEME']; $server_name = $_SERVER['SERVER_NAME']; $dir = (is_localhost()) ? dirname($_SERVER['REQUEST_URI']) : NULL; return $scheme . '://' . $server_name . $dir; } print home_url(); # Dir where executed home_url() : administrator # Localhost output: http://localhost/project_name/sub_project_name/administrator # Live output: http://www.project_name.com # Expected output # Localhost: http://localhost/project_name/sub_project_name # Live: http://www.project_name.com/sub_project_name ?> Quote Link to comment https://forums.phpfreaks.com/topic/298094-localhost-url-with-project-and-sub-project-name/ Share on other sites More sharing options...
hansford Posted September 8, 2015 Share Posted September 8, 2015 (edited) What results are you expecting? dirname() // returns the path to the parent directory of the passed path value Edited September 8, 2015 by hansford Quote Link to comment https://forums.phpfreaks.com/topic/298094-localhost-url-with-project-and-sub-project-name/#findComment-1520482 Share on other sites More sharing options...
jason_15 Posted September 8, 2015 Author Share Posted September 8, 2015 What results are you expecting? dirname() // returns the path to the parent directory of the passed path value # Expected output # Localhost: http://localhost/project_name/demo # Live: http://www.project_name.com/demo Quote Link to comment https://forums.phpfreaks.com/topic/298094-localhost-url-with-project-and-sub-project-name/#findComment-1520488 Share on other sites More sharing options...
scootstah Posted September 8, 2015 Share Posted September 8, 2015 The easiest way to handle stuff like this is to use a config file that has different values depending which environment it's in. So something like: config.php on development environment <?php define('BASEURL', 'http://localhost/project_name/sub_project_name'); config.php on live environment <?php define('BASEURL', 'http://www.project_name.com/sub_project_name'); index.php <?php require 'config.php'; echo BASEURL; Quote Link to comment https://forums.phpfreaks.com/topic/298094-localhost-url-with-project-and-sub-project-name/#findComment-1520489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.