jaxdevil Posted July 23, 2008 Share Posted July 23, 2008 I am making a function to redirect the page to http://www.myserver.com/index.php?region=en if the page is http://www.myserver.com/index.php , but I want the function to determine the url and page itself automatically, so if I change sites or urls with the script it will still verify that page. Here is what I have now... <?php if ($region=="") { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=http://$_SERVER['HTTP_HOST']/index.php?region=en\">"; } ?> But see, I need whatever that is thats like $_SERVER['HTTP_HOST'] but pulls up the actual pages full path, so it will check and redirect ONLY is the page is the root page, the main page. What is that thing? Quote Link to comment https://forums.phpfreaks.com/topic/116170-solved-display-file-path/ Share on other sites More sharing options...
jaxdevil Posted July 23, 2008 Author Share Posted July 23, 2008 Actually I figured what the call was, but I can't get it to work. Here is what I am trying now. It doesn't work, it just breaks the script and causes a blank screen: <?php $path = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if ($path=="http://".$_SERVER['HTTP_HOST']) { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=http://$_SERVER['HTTP_HOST']/index.php?region=en\">"; } ?> <?php $path = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if ($path=="http://".$_SERVER['HTTP_HOST']."/index.php") { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=http://$_SERVER['HTTP_HOST']/index.php?region=en\">"; } ?> <?php $path = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if ($path=="http://".$_SERVER['HTTP_HOST']."/") { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=http://$_SERVER['HTTP_HOST']/index.php?region=en\">"; } ?> <?php $path = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if ($path=="http://".$_SERVER['HTTP_HOST']."/index.php?region=") { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=http://$_SERVER['HTTP_HOST']/index.php?region=en\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116170-solved-display-file-path/#findComment-597388 Share on other sites More sharing options...
unkwntech Posted July 23, 2008 Share Posted July 23, 2008 If you are at http://domain.tld/index.php $_SERVER['SCRIPT_NAME'] == index.php Quote Link to comment https://forums.phpfreaks.com/topic/116170-solved-display-file-path/#findComment-597394 Share on other sites More sharing options...
jaxdevil Posted July 23, 2008 Author Share Posted July 23, 2008 Ok, let me explain a little more what I am trying to do. I had figured out that this here: "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; Gives me what I need, but I can't seem to get the entire function to work. What I have is a site that sets the language file to pull from based on what the variable region is set to in the url. The problem is on the main page no region file is set. So I am looking to make a function that detects if the current location is http://thewebsiteaddress.com/index.php or if the location is http://thewebsiteaddress.com/index.php?region= (i.e. region is blank) and if those are true it redirects the page to http://thewebsiteaddress.com/index.php?region=en (for region is english) BUT I don't want to make the websiteaddresses o be static as I want to be able to load this entire site onto different sites without having to go back in and change the url on these pages. I posted the code I tried but that was not working. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/116170-solved-display-file-path/#findComment-597522 Share on other sites More sharing options...
jaxdevil Posted July 23, 2008 Author Share Posted July 23, 2008 Ok, here is something that is working. I had to put it on the main index page AND the header file: <? if ( $region == "") { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?region=en&medical=".$medical."\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116170-solved-display-file-path/#findComment-597535 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.