Jump to content


Photo

Help with HTTP_HOST ?


  • Please log in to reply
4 replies to this topic

#1 macdude

macdude
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 July 2006 - 01:33 PM

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 ?


#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 07 July 2006 - 02:32 PM

"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
<?php
print_r($_SERVER);
?>

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.
<?php
$_SERVER['HTTP_HOST'] = 'foo';
?>

You can also put it in a constant yourself for use throughout your script
define('TRUE_HOST', '195.x.x.x');
echo TRUE_HOST;
define()

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.

#3 macdude

macdude
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 July 2006 - 11:44 AM

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.

#4 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 10 July 2006 - 11:53 AM

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.
"Confidence in the face of risk."

#5 macdude

macdude
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 July 2006 - 12:20 PM

Thanks for that...works just the way i want it to...

Simon.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users