[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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?
0
tilmes
Asked:
tilmes
  • 7
  • 4
1 Solution
 
Oliver_DornaufCommented:
$_SERVER['SERVER_NAME'] holds the server name
$_SERVER['PHP_SELF'] holds the scrip name (incl. path)
0
 
tilmesAuthor Commented:
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";

}
0
 
Marcus BointonCommented:
Putting 2 and 2 together...

if ($_SERVER['SERVER_NAME' == 'abcd.com') {
     print "here is text";
}
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
tilmesAuthor Commented:
I get an error with this code.
0
 
tilmesAuthor Commented:
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.
0
 
Marcus BointonCommented:
Oops, bad copy/paste, missed 1 char: It should be

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

If you want to see what your server thinks it is, just try:

echo $_SERVER['SERVER_NAME'];
0
 
tilmesAuthor Commented:
Thankns Squinky,
it works.
0
 
tilmesAuthor Commented:
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
0
 
Marcus BointonCommented:
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.
0
 
tilmesAuthor Commented:
The code must be included in file, It must be in index.php
The text must not show under other directories.
0
 
Marcus BointonCommented:
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.
0
 
tilmesAuthor Commented:
Hi Squinky,

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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now