/    Sign up×
Community /Pin to ProfileBookmark

Domain extension switch

[B]Hi[/B],

Trying to fiddle with a script [B]Jona[/B] so kindly created for me.
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/”);

?>
[/code]

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?

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [font=trebuchet ms]Try...[/font]

[code=php]
<?php
$ref = str_replace(".dk", ".info", $_SERVER["HTTP_REFERER"]);
header("Location: $ref");
?>
[/code]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [i]Originally posted by Jona [/i]

[B][font=trebuchet ms]Try...[/font]



[code=php]
<?php
$ref = str_replace(".dk", ".info", $_SERVER["HTTP_REFERER"]);
header("Location: $ref");
?>
[/code]
[/B][/QUOTE]


Let's say the URL goes like this: [b]Edit:[/b] URL removed.

...and I would like it to be: [b]Edit:[/b] URL removed.

Do you think a simple adjustment of the domain extensions would suffice? (I ask because I have tried and something must be wrong in what I'm doing).
Copy linkTweet thisAlerts:
@LaChikoOct 03.2004 — <?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?
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [code=php]
<?php
$ref = str_replace(".info", ".dk", __FILE__);
header("Location: $ref");
?>
[/code]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [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]


You may try it by ([b]Edit:[/b] URL removed) clicking here, then click the Danish flag in the upper left corner. I have used the above code for the 'lang_switch.php' file.

The PHP switch I would like to create should switch the domain extension only (.info to .dk) and show me the Danish version of the same page at the same location - just with another domain.

The other domain is a mirror site in the Danish language. This way I can utilize both domains since I'm not able to use mod_rewrite on the server hosting the .info domain.
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [i]Originally posted by Jona [/i]

[B][code=php]
<?php
$ref = str_replace(".info", ".dk", __FILE__);
header("Location: $ref");
?>
[/code]
[/B][/QUOTE]


[font=trebuchet ms]Did you try the above?[/font]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [i]Originally posted by Jona [/i]

[B][font=trebuchet ms]Did you try the above?[/font] [/B][/QUOTE]


Yes. It takes me to the root of the directory where the 'lang_switch.php' file is situated.
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [font=trebuchet ms]Ah, I see. Try:[/font]

[code=php]
<?php
$loc = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
$loc = str_replace(".info", ".dk", $loc);
header("Location: $loc");
?>
[/code]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [i]Originally posted by Jona [/i]

[B][font=trebuchet ms]Ah, I see. Try:[/font]



[code=php]
<?php
$loc = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"];
$loc = str_replace(".info", ".dk", $loc);
header("Location: $loc");
?>
[/code]
[/B][/QUOTE]


Nope, doesn't work. The file is uploaded right now. ?
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [font=trebuchet ms]Actually it works, but it would create a never-ending loop if you added the same page on the other server; use $_SERVER["HTTP_REFERER"] instead of $_SERVER["PHP_SELF"] in the above script, and see if it works. ? [/font]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [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]


Well, I don't understand this. Since the PHP script is activated by a hyperlink, it should be possible to see the other page without looping, since the same hyperlink on the second page should be activated by clicking it to get back to the original page from where one started out in the first place.

[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]


I'm sorry, no go... ?
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [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]
<?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]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [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]
<?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]
[/QUOTE]


[B]Jona[/B], many thanks for your efforts. ?

First of all, I'm not sure what you mean by header include. Is that an include I place within the META or something else?

Secondly, the language of the .dk domain is Danish. Just to avoid misunderstandings. ?

And yes, I'm a complete noob when it comes to PHP. ?

What does this script do you are suggesting?
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [font=trebuchet ms]By header includes, I mean, do you include a header file on each page?[/font]

[code=php]
<?php
include ("inc/header.php");
?>
<h2>Hello, World</h2>
<p>What's up?</p>
<?php
include ("inc/footer.php");
?>
[/code]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [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]


Oh, I see. I use SSI on my ordinary HTML and the PHP scripts I use have built in code for includes that are not standard PHP code. IN my PHP scripts it is not possible to include PHP tags.

On .shtml pages, which I'm trying to work on here, I have four includes working - META, menu, a topline bar and footer. The actual header (like <h1>) is standalone on each page since the header is identical to the title - and they are different on each page.
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — If I understand you correctly, you want me to include a PHP file somewhere in the beginning of a page, am I right?
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [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]

<i>
</i>&lt;a href="lang_switch.php?loc=&lt;?php echo $_SERVER["PHP_SELF"]; ?&gt;" title="Danish version."&gt;&lt;img src="/i/danish_flag.gif" alt="" /&gt;&lt;/a&gt;


[font=trebuchet ms]And your lang_switch.php file would look something like this.[/font]

[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]
Copy linkTweet thisAlerts:
@philawebauthorOct 03.2004 — [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]


That doesn't work either.

Can I PHP include within a SSI include file with prefixes?

The file is SHTML and I have never tried to include a PHP file to this format.

This is the code part of the 'topline' SSI include:

[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>&nbsp;&nbsp;</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]
Copy linkTweet thisAlerts:
@philawebauthorOct 04.2004 — [B]Jona[/B],

Thanks for your help anyway even though it didn't work out. ?
Copy linkTweet thisAlerts:
@JonaOct 04.2004 — [font=trebuchet ms]Okay...[/font]
×

Success!

Help @philaweb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...