Jump to content

Recommended Posts

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

?>

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;
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.