macdude Posted July 7, 2006 Share Posted July 7, 2006 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/13952-help-with-http_host/ Share on other sites More sharing options...
shoz Posted July 7, 2006 Share Posted July 7, 2006 "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]<?phpprint_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. Quote Link to comment https://forums.phpfreaks.com/topic/13952-help-with-http_host/#findComment-54399 Share on other sites More sharing options...
macdude Posted July 10, 2006 Author Share Posted July 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13952-help-with-http_host/#findComment-55480 Share on other sites More sharing options...
micah1701 Posted July 10, 2006 Share Posted July 10, 2006 if you know that the port is always 8080just do$_SERVER['SERVER_ADDR'].":8080"to join the string text on to your variable string. Quote Link to comment https://forums.phpfreaks.com/topic/13952-help-with-http_host/#findComment-55485 Share on other sites More sharing options...
macdude Posted July 10, 2006 Author Share Posted July 10, 2006 Thanks for that...works just the way i want it to...Simon. Quote Link to comment https://forums.phpfreaks.com/topic/13952-help-with-http_host/#findComment-55494 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.