PDA

View Full Version : Please Help



gur
04-02-2005, 09:17 PM
Please Help i need a PHP script, i hace registered my own domai name www.gur.in or htp://www.gur.in and i am hosting my site at cjb.cc and the url for it is http://gtec.cjb.cc i want a script that if someone types http://gtec.cjb.cc in the address bar it sould display a message that the site has new domain name which is gur.in and on my index.htm i have mentioned that i have registered my own domain but it should not appear if someone has typed gur.in in the address bar please help me

mwinter
04-02-2005, 10:12 PM
[...] i need a PHP scriptPerhaps a better approach would be to use URL rewriting to automatically alter the URL. However, if your intent is to explicitly point out the new domain name, you can check what was used to request a PHP script using the HTTP_HOST server variable.


$_SERVER['HTTP_HOST']Exactly how you'd go about using this would depend on how you'd want to present this information.

If you want a forwarding page, it would probably be necessary to use URL rewriting anyway: rewrite to a common forwarding page which presents a link that can be used to continue to the original with the new domain.

Before you can even consider using URL rewriting, you must make sure your host supports mod_rewrite with .htaccess files.

Mike

jscheuer1
04-02-2005, 10:20 PM
I don't do PHP but in JavaScript:

<script>
if (parent.location.href=='http://gtec.cjb.cc/index.htm') //use the correct filename here
document.write('your message goes here')
</script>perhaps this can be adapted to PHP.

mwinter
04-02-2005, 10:47 PM
I don't do PHP but in JavaScript:
<script>
if (parent.location.href=='http://gtec.cjb.cc')
document.write('your message goes here')
</script>
perhaps this can be adapted to PHP.Yes:


<?php if('gtec.cjb.cc' === $_SERVER['HTTP_HOST']) { ?>
<!-- Content to insert here. -->
<?php } ?>would perform basic content insertion.

This wouldn't work with HTTP/1.0 clients as they don't send a Host header. However, I don't think there are that many HTTP/1.0 clients left - I'm not honestly sure when HTTP/1.1 became widely implemented.


if (parent.location.href=='http://gtec.cjb.cc/index.htm') //use the correct filename hereAn alternative would be to do a substring search:


if(-1 != document.URL.indexOf('gtec.cjb.cc')) {Mike

jscheuer1
04-03-2005, 03:48 AM
if(-1 != document.URL.indexOf('gtec.cjb.cc')) {This will always be true as the redirect places that document in a frame. That's why I used 'parent'. I don't know PHP but, if you were assuming that these were two separate documents, your PHP code should be adjusted as well. This is the second time, recently, I've run across redirects being accomplished simply by placing the original document in a frame so, I get the idea it is rather routine. I for one, vote against this tactic.

jscheuer1
04-03-2005, 05:20 AM
I got another one that is even better for detecting the presence of the containing frame.


<script>
if (parent.location.href==location.href)
document.write('Your content here');
</script>

This will only write the content if the document is not in the redirect (or some other) frame. Now, since we're supposed to be on PHP, can this be done with PHP? Also, in a somewhat related matter, I've noticed that my PHP list program uses extensive JavaScript in its templates yet still performs with JavaScript turned off. Are there some portions of JavaScript that act as server side when used with (or without) PHP, or is the PHP program just compensating when JavaScript is turned off by using different methods?

mwinter
04-03-2005, 10:29 AM
This will always be true as the redirect places that document in a frame.Oh, I see. The OP is using cloaking, not redirection. Well no, PHP can do nothing here as the request to the server will always be under the gtec.cjb.cc domain.

Mike