0

I learned and worked with Code Igniter before so I know how to do

in CI we call this function

   <?php echo base_url('sample.php');?>

but how to do that in pure PHP ?

I tried to include like this

<?php include('../../sample.php');?>

Is there any better solution? Thanks

4

1 回答 1

3

Define the base url as a string, then append that constant to your include calls.

define("BASE_URL", "/var/www/httpdocs/");
include(BASE_URL . 'sample.php');

Its worth noting that once BASE_URL is defined it can be used anywhere.

EDIT

Your last comment shows that you are unsure of what you are doing. Includes are done via the filesystem on the server or your local machine. They are nothing to do with the URL the domain or localhost.

// This means nothing as the include is done via the file system not via the URL
define("BASE_URL", "localhost:80");
include(BASE_URL . 'sample.php');

// This is what you need, a path on your file system to your included file
define("BASE_URL", "/var/www/httpdocs/");
include(BASE_URL . 'sample.php');
于 2013-08-02T18:12:20.790 回答