Link to home
Start Free TrialLog in
Avatar of tilmes
tilmesFlag for Germany

asked on

shows text only in main domain

Hello,
i need to show texts only at main home page like www.abcd.com, not at www.abcd.com/something/
This info will be inserted in index.php.
How can i do this?
Avatar of Oliver_Dornauf
Oliver_Dornauf
Flag of Afghanistan image

$_SERVER['SERVER_NAME'] holds the server name
$_SERVER['PHP_SELF'] holds the scrip name (incl. path)
Avatar of tilmes

ASKER

Hi Oliver,

would you please complete the code, which i can use it directly in script? like this kind of,
if ($sitename=abcd.com
{
      print "here is text";

}
Avatar of Marcus Bointon
Putting 2 and 2 together...

if ($_SERVER['SERVER_NAME' == 'abcd.com') {
     print "here is text";
}
Avatar of tilmes

ASKER

I get an error with this code.
Avatar of tilmes

ASKER

if ($_SERVER['SERVER_NAME' == 'abcd.com']) {
     print "here is text";
}

I used both www.abcd.com and abcd.com
but it do not print anything.
ASKER CERTIFIED SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tilmes

ASKER

Thankns Squinky,
it works.
Avatar of tilmes

ASKER

Hi Squinky,

there is an problem. The text shows also in second level of directories. It should not show in directory like abcd.com/test/
or abcd.com/text.html

I must show only under abcd.com
It's only showing because you're telling it to. If you don't want to display it, just don't include that code in files below the root level.
Avatar of tilmes

ASKER

The code must be included in file, It must be in index.php
The text must not show under other directories.
OK, in that case look at the parse_url() function - if the path is "/", print the stuff, otherwise don't:

http://www.php.net/manual/en/function.parse-url.php

$pi = parse_url($_SERVER['REQUEST_URI']);
if ($_SERVER['SERVER_NAME'] == 'abcd.com' and $pi['path'] == '/') {
     print "here is text";
}

If it doesn't work, read the docs some more.
Avatar of tilmes

ASKER

Hi Squinky,

it works fine now. Thanks.
Would you help me with perl for same work?
I have posted new quetion.