Click to See Complete Forum and Search --> : Domain Script


Jick
09-06-2003, 04:02 PM
<SCRIPT TYPE="text/javascript">

<!--

if (parent.location.href == self.location.href) {

if (window.location.replace)

window.location.replace('http://www.thedandygroup.com');

else

// causes problems with back button, but works

window.location.href = 'http://www.thedandygroup.com';

}

// -->

</SCRIPT>
Someone gave me this script which is sapposed to make it so when I go to www.thedandygroup.com in my browser it will make it stay as www.thedandygroup.com instead of changing it to www.host123.com/sites/mysite/mypage.html like it is doing now. The only problem is that it has a few bugs like "causes problems with back button, but works" and I also needed it in php so this will work for all users to my site and not just people with javascript enabled. Can someone please help me fix the bugs in it and convert it to php. I would greatly appreciate it. I cannot ask the guy who gave it to me because he does not know php. Thanks for any help. :D

pyro
09-06-2003, 05:17 PM
Look into header() (http://us2.php.net/manual/en/function.header.php) to redirect the page and use something like $_SERVER['PHP_SELF'] (http://us2.php.net/manual/en/reserved.variables.php) to get the current page...

Jick
09-06-2003, 06:47 PM
I found this on the header link you gave me:<?php
header("Location: http://".$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/".$relative_url);
?>
Is this the correct code or close to it?

Jick
09-07-2003, 12:58 AM
Could anybody let me know if the code in my last post is what I need? Thank you. :D

pyro
09-07-2003, 04:06 PM
Looking at it again, I'm not sure I know entirely what you are trying to do, but I'm not sure you can do it with PHP either way, as it appears you want to compare the current page's location with the parent location. Anyway, this JavaScript should work for you (and not mess up the back button):

<script type="text/javascript">
if (parent.location.href == self.location.href) {
window.location.replace('http://www.thedandygroup.com');
}
</script>

Jick
09-07-2003, 04:47 PM
I have registered a domain which is www.thedandygroup.com and I have it so when you goto www.thedandygroup.com it forwards you to the host where my files are which is a way long address like www.host123.com/sites/mysite/mypage.html. I'm trying to make it so when you go to www.thedandygroup.com the address will stay as www.thedandygroup.com instead of changing to www.host123.com/sites/mysite/mypage.html like it is doing now!

pyro
09-07-2003, 06:25 PM
That is probably not a scripting issue, but rather something that is happening on the server... Most likely the way your hosting is set up.