Page 1 of 1

$HTTP_HOST issue ?

Posted: Sat Jul 08, 2006 10:27 am
by bplymale
I am new to php programming and I am seeing an issue I think?

First Test:
code:
$site[homeurl] = ("http://".$HTTP_HOST."".dirname($SCRIPT_NAME));

Result:
http:// http://www.xyz.com/script
* notice the extra leading http:// in the return value.

Second Test:
$site[homeurl] = ($HTTP_HOST."".dirname($SCRIPT_NAME));

Result:
test.xyz.com/script

I am curious as to why in the first test it adds another "http://"
[/b]http://[/b] http://www.xyz.com/script

I have read the documentation and this should not add the extra "http://" but I do not understand why?

php version:
PHP 5.0.4 (cli) (built: Jun 28 2005 22:35:56)

Apache Version:
2.0.55

OS Version:
Solaris 10/05

Note: "I have changed the real domain to xyz.com".

Thank you in advance for any assistance.

Bob

Posted: Sat Jul 08, 2006 11:25 am
by bdlang
Try

Code: Select all

$site['homeurl']= "http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}";
If you have access to $HTTP_HOST, you're using register_globals = On, which is a known security issue, I suggest you correct it prior to any 'real world' development, anything that will exist on a public server.

Posted: Sat Jul 08, 2006 11:38 am
by bplymale
Thanks bdland,

I will understand the global issue.

After making the changes you suggested:

Result:
http://www.xyz.com/script/index.php http://www.xyz.com/script/index.php

Posted: Sat Jul 08, 2006 11:55 am
by bdlang
Ok, so if you want strictly the directory, then use a variant on your original

Code: Select all

$site['homeurl']= "http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['SCRIPT_NAME']);
..add the ending slash

Code: Select all

$site['homeurl']= "http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['SCRIPT_NAME']) . '/';

Posted: Sat Jul 08, 2006 1:09 pm
by bplymale
bdlang, thanks that worked!

Now a newbie question on my original issue so I can hopefully understand if you do not mind.

Why would my first test suing the following format add an extra leading http:// ?
$site[homeurl] = ("http://".$HTTP_HOST."".dirname($SCRIPT_NAME));

Result:
http:// http://www.xyz.com/script


When this one does not even show a leading http://
Second Test:
$site[homeurl] = ($HTTP_HOST."".dirname($SCRIPT_NAME));

Result:
test.xyz.com/script

Thanks,

Bob