Forum Moderators: open

Message Too Old, No Replies

Looking for script

One that displays the domain of any given site

         

limbo

8:38 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When I register a domain I have a page that is automatically generated (customisable) by my hosts along the lines of:

this domain has been registered by www.mysite.com for more info....

I would like a script (JS or otherwise) that displayed:

www.newdomain.com has been registered by www.mysite.com for more info....

Anyone got a method for a call like this? Cheers, Limbo.

dragonthoughts

8:47 am on Sep 21, 2005 (gmt 0)

10+ Year Member



You could get the value from a perl CGI returning $ENV{SERVER_NAME}

or using SSI and the SERVER_NAME value

limbo

9:41 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds good. What does it all mean?

dragonthoughts

10:00 am on Sep 21, 2005 (gmt 0)

10+ Year Member



This isn't really a Javascript solution, so is a little off topic.

The server knows what it is called. So server-side technologies can return return the information for you.

If you hosting your site on an Apache server, with Server Side Includes (SSI) enabled then if your display page includes the line:


This site is called <!--#echo var="SERVER_NAME" -->

You would get the result you are looking for, because the server would replace the comment text by wwww.yourdomain.com or whatever.

The perl solution is a little more involved.

For a good reference on the basics of SSI, have a look at Apache's own tutorial at [httpd.apache.org ]

limbo

10:55 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for your time. This seems a lot of effort for a such an action - could a similar thing be done using php?

dragonthoughts

12:55 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



Certainly, in PHP, the magic value is in

$_SERVER['SERVER_NAME']

if you are running PHP version 4.10 or later then it is in

$HTTP_SERVER_VARS['SERVER_NAME']

For further details, see the PHP documentation at [uk.php.net ]

My personal choice is to use SSI for simple tasks, and PHP for anything more intelligent, but that's also related to how the servers are configured.

Mike12345

1:55 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



The following Javascript would do the trick also. Although server side solution is more reliable.

<script>document.writeln(location.hostname, ' has been registered by www.mysite.com for more info.... ');</script>

limbo

4:53 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Dragonthoughts. the PHP example sounds ike it woud suit me, Could you place the snippet you describe into a basic example (I'm a a designer not programmer) - I have toyed with a php page but had no luck executing the command - I am probably missing something very obvious.

Mike you JS version worked a treat, thank you.

dragonthoughts

7:56 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Limbo, assuming you have a recent edition of PHP, what you need is:

<p>
<em><?php print "$_SERVER['SERVER_NAME']"?></em> has been registered by www.mysite.com for more info...
</p>

if you have an older version of PHP then try:
<p>
<em><?php print "$HTTP_SERVER_VARS['SERVER_NAME']"?></em> has been registered by www.mysite.com for more info...
</p>
There are other alternatives, but oen of these will work.

limbo

8:16 am on Sep 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Dragonthoughts - But when i use either I get his error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sites/mysite.com/public_html/filemane.php on line 40

I'm still missing something?

Mike12345

11:00 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Try it this way:

<p>
<em><?php echo $_SERVER['SERVER_NAME']?></em> has been registered by www.mysite.com for more info...
</p>

limbo

11:12 am on Sep 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks mike. That made all the difference, ta, Limbo.