Menu
[B]Hi
Trying to fiddle with a script [B]Jona
This is my first try at adjusting PHP code to my needs… ?
[code=php]
<?php
$ref = str_replace(“.dk”, “.info”);
header(“http://www.lettonica $ref/”);
?>
Well, the above code doesn’t work, but I hope you can see that I’m trying to switch the domain extension (so far so good), but am having problems now on how to preserve the refered end part of the URL after the last slash “/”.
Anyone who want to help me out?
[code=php]
<?php
$ref = str_replace(".dk", ".info", $_SERVER["HTTP_REFERER"]);
header("Location: $ref");
?>
[/code]
[i]Originally posted by Jona [/i]
[B][font=trebuchet ms]Try...[/font]
[code=php]
[/B][/QUOTE]
<?php
$ref = str_replace(".dk", ".info", $_SERVER["HTTP_REFERER"]);
header("Location: $ref");
?>
[/code]
[code=php]
<?php
$ref = str_replace(".info", ".dk", __FILE__);
header("Location: $ref");
?>
[/code]
[i]Originally posted by LaChiko [/i]
[B]<?php
$ref = str_replace(".dk", ".info", $_SERVER["HTTP_REFERER"]);
header("Location: $ref");
?>
i have no idea on how php works but the code seems pretty straight forward it searches for the string .dk and replaces it with .info what do you want it to do? [/B][/QUOTE]
[i]Originally posted by Jona [/i]
[B][code=php]
[/B][/QUOTE]
<?php
$ref = str_replace(".info", ".dk", __FILE__);
header("Location: $ref");
?>
[/code]
[i]Originally posted by Jona [/i]
[B][font=trebuchet ms]Did you try the above?[/font] [/B][/QUOTE]
[code=php]
<?php
$loc = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
$loc = str_replace(".info", ".dk", $loc);
header("Location: $loc");
?>
[/code]
[i]Originally posted by Jona [/i]
[B][font=trebuchet ms]Ah, I see. Try:[/font]
[code=php]
[/B][/QUOTE]
<?php
$loc = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
$loc = str_replace(".info", ".dk", $loc);
header("Location: $loc");
?>
[/code]
[i]Originally posted by Jona [/i]
[font=trebuchet ms]Actually it works, but it would create a never-ending loop if you added the same page on the other server[/font][/Quote]
[i]Originally posted by Jona [/i]
[font=trebuchet ms]use $_SERVER["HTTP_REFERER"] instead of $_SERVER["PHP_SELF"] in the above script, and see if it works. ? [/font][/QUOTE]
[code=php]
<?php
// header file
$loc = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
if(isset($_GET["lang"]) && $_GET["lang"] == "dutch"){
$loc = str_replace(".info", ".dk", $loc);
header("Location: $loc");
} else if($_GET["lang"] == "english") {
$loc = str_replace(".dk", ".info", $loc);
header("Location: $loc");
}
?>
[/code]
[i]Originally posted by Jona [/i]
[font=trebuchet ms]Do you use header includes files? If so, you can search the query string for something such as "lang" and redirect if it is "dutch." You can do this using the following code. The HTTP_REFERER is not very reliable, so I am suggesting an alternative.[/font]
[code=php]
[/QUOTE]
<?php
// header file
$loc = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
if(isset($_GET["lang"]) && $_GET["lang"] == "danish"){
$loc = str_replace(".info", ".dk", $loc);
header("Location: $loc");
} else if($_GET["lang"] == "english") {
$loc = str_replace(".dk", ".info", $loc);
header("Location: $loc");
}
?>
[/code]
[code=php]
<?php
include ("inc/header.php");
?>
<h2>Hello, World</h2>
<p>What's up?</p>
<?php
include ("inc/footer.php");
?>
[/code]
[i]Originally posted by Jona [/i]
[font=trebuchet ms]By header includes, I mean, do you include a header file on each page?[/font][/QUOTE]
<i>
</i><a href="lang_switch.php?loc=<?php echo $_SERVER["PHP_SELF"]; ?>" title="Danish version."><img src="/i/danish_flag.gif" alt="" /></a>
[code=php]
<?php
if(isset($_GET["loc"])){
$loc = "http://".$_SERVER["SERVER_NAME"].$_GET["loc"];
$loc = str_replace(".info",".dk",$loc);
header("Location: $loc");
} else {
die("Error");
}
?>
[/code]
[i]Originally posted by Jona [/i]
[font=trebuchet ms]Well, if you can't use includes, you can make each link static, with a query string of the relative URL, and add the appropriate prefix. So your links would look like:[/font][/QUOTE]
[CODE]<div class="topline">
<div class="language_switch"><a href="http://www.lettonica.info/js/lang_switch.php" title="Dansk udgave!"><img src="http://www.lettonica.info/pix/da_flag.gif" alt="Dansk udgave!" style="border:0" /></a> </div>
<div class="tellafriend"><a href="http://www.lettonica.info/recommend/" title="Tell a friend about this page!">Tell A Friend!</a></div>
</div>[/CODE]
0.1.9 — BETA 5.18