Jump to content
Larry Ullman's Book Forums

Recommended Posts

I have a constant building a dynamic base_url:

 

	define('BASE_URL', "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);

 

 

The current base_url

 "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test.php/index.php"

 

 

I've used:

echo(BASE_URL . '/index.php' . "<br />"); // Define the URL:

echo str_ireplace('htdocs/','', BASE_URL ); //Not the desired result

 

and arrived at:

 

 "http://training:8888/php/PHP6:MySQL%205/16/user_registration/test.php"

 

I'm having issues, adapting the str_ireplace() function to remove all segments after

"htdocs" so another uri can be appended:

 

	$url = BASE_URL . '/somepage.php'; // Define the URL:

 

"http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/somepage.php."//Desired result

 

Happy New Year!

Link to comment
Share on other sites

The "." at the end was not desired :)

 

I'm trying to trim the result of

 "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test.php/index.php"

 

to just the requesting directory:

 "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs" //desired base URL

 

Allowing me to append any document file:

 

$url = BASE_URL . '/somepage.php'; // Define the URL

 

Hope I clarified my request. Thanks for the reply and inspiration.

 

PS: I'm experimenting with http_build_url();

 

Happy New Year!

Link to comment
Share on other sites

Okay, that makes more sense, but should it really be "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test.php/index.php" or should that be "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test/index.php". And if it's the latter, should that be trimmed down to "http://training:8888/php/PHP6:MySQL%205/16/user_registration/htdocs/test/"?

Link to comment
Share on other sites

I'm attempting to trim away "test.php" so that I can append "somepage.php". Thus making the base_url usable in any config file. I've seen the same in frameworks, wanting to recreate it "old school."

 

I appreciate frameworks, but still like making apps "from scratch" when time permits, having been with your publications since PHP 4.

 

Thanks Again!

Link to comment
Share on other sites

The $base_url should NOT include test.php, however when using:

define('BASE_URL', "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);

 

I get the full path to the requesting document file, I'm trying to strip in this case (test.php), so it can be replaced with

 

$url = BASE_URL . '/whateverpage.php';

 

Again, thanks for your patience.

Link to comment
Share on other sites

 Share

×
×
  • Create New...