Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.