Jump to content

Archived

This topic is now archived and is closed to further replies.

macdude

Help with HTTP_HOST ?

Recommended Posts

Any one help me with this problem please !!  Ok, how do i get the 'HTTP_HOST' variable to allways be a specfic address rather than the one that is the current url ? For example,

We are running some project management software that is web based and use's php, we have access to it inside work on a server, the server address is say http://195.192.1.1:80, we can also access it from home on a pass through which is say http://81.254.101.51:80, now the problem is if you work on a project from home and get email notification to your work email that a change has been made, php send out a mail with a link to click to see the changes made but that link is the http://81.254.101.51:80 link and not the http://195.192.1.1:80, so in work you cant click the link to go to the internal server because the 'HTTP_HOST' takes the link from where the web url is ? How can i force the 'HTTP_HOST' to allways be http://195.192.1.1:80 ?

Share this post


Link to post
Share on other sites
"HTTP_HOST" is basically a user supplied value. Perhaps "REMOTE_ADDR" or "SERVER_ADDR" will have the value you're look for. Do a print out of the $_SERVER array to see what the differences are when going through 81.x and 195.x
[code]
<?php
print_r($_SERVER);
?>
[/code]

The HTTP_HOST value can be overridden, but you probably don't want to do that because if the value is used elsewhere it's more than likely that the value you want is the original one.
[code]
<?php
$_SERVER['HTTP_HOST'] = 'foo';
?>
[/code]

You can also put it in a constant yourself for use throughout your script
[code]
define('TRUE_HOST', '195.x.x.x');
echo TRUE_HOST;
[/code]
[url=http://www.php.net/define]define()[/url]

Harcoding the value in the section of the script that creates the link for the email is also an option if it's unlikely that you need the true value anywhere else.

EDIT: You may find it more convenient to create two links. One that's for accessing from home and one for accessing from work. So that if the email is accessed from home you'll still be able to have easy access.

Share this post


Link to post
Share on other sites
Thanks for that, the variable 'SERVER_ADDR' works however i need to add a specific port to that address also for example http://192.x.x.x:8080 because of the way the server is set up to only allow trafic on that port for this software, can you help ?

Simon.

Share this post


Link to post
Share on other sites
if you know that the port is always 8080

just do

$_SERVER['SERVER_ADDR'].":8080"

to join the string text on to your variable string.

Share this post


Link to post
Share on other sites

×

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.