Jump to content

[SOLVED] Display file path


jaxdevil

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/116170-solved-display-file-path/
Share on other sites

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\">";

}

?>

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?

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."\">";
}
?>

Archived

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

×
×
  • Create New...

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.