Solved

Only Show Paragraph for Specific URL

Posted on 2006-06-29
9
292 Views
Last Modified: 2012-08-13
Hi, thanks in advance for your help.

There is a paragraph that I want to only have shown on the home page of my site. However because of the way the site designer developed it, the paragraph I wrote appears on every single page of the entire site.

What I am looking for is a conditional statement that will check to see if it's the home page in four different variations: i.e. http://www.mysite.com/, http://mysite.com, http://www.mysite.com/index.php, and http://mysite.com/index.php.

If it finds that the current page is any of those referring to the homepage, I'd like to echo about a three paragraphs worth of introductory material. For the rest of the pages, it should not show up at all.

I appreciate any help I can get on this. Thanks.
0
Comment
Question by:frogpad
  • 5
  • 3
9 Comments
 
LVL 16

Accepted Solution

by:
dr_dedo earned 30 total points
ID: 17014829
do this if condition

if (echo $_SERVER['PHP_SELF'] != 'index.php') {
hide the paragraphs
} else {
show them
}
0
 
LVL 37

Assisted Solution

by:Harisha M G
Harisha M G earned 20 total points
ID: 17014845
Hi, please try this:

1) Put

        echo $_SERVER['PHP_SELF'];

on the index page, and see what it prints.

2) Assuming it prints out "/index.php", put the code as follows..

...
if($_SERVER['PHP_SELF'] == "/index.php")
{
    echo "Introduction";
}
...



---
Harish
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17014850
dr_dedo, sorry. Didn't refresh
0
 

Author Comment

by:frogpad
ID: 17015160
Hi thanks for your help.

One thing I should have noted is that this is a blog site. Therefore every single page on the site hypothetically has an index.php file name. I.e. a link to blue widgets page would look like www.mysite.com/blue-widgets/index.php.

How would I adjust the code to make it so it only identifies the homepage URL? Thanks so much.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 37

Expert Comment

by:Harisha M G
ID: 17015180
Did you ty the suggestion ? Use 'SCRIPT_FILENAME' instead of 'PHP_SELF'

You will get the absolute path name, which you can compare easily. Ie., for the first you'll get /index.php, and for the second, you'll get /blue-widgets/index.php
0
 

Author Comment

by:frogpad
ID: 17015835
Sorry guys, I tried both and it's still not working. It seems as though no matter what page I am on, the script echos the same 'SCRIPT_FILENAME' which is /home/computer/public_html/index.php, problem is, the conditional turns out to be true no matter the URL and returns that same exact line.

Hopefully there is a way to resolve this issue. Thanks so much.
0
 

Author Comment

by:frogpad
ID: 17015849
I want to point at that this prob occurs for both SCRIPT_FILENAME and PHP_SELF.

In the case of PHP_SELF, it returns "index.php" no matter which blog page I have surfed to. I am really confused.
0
 

Author Comment

by:frogpad
ID: 17015938
Alright guys, another thread on this site helped me find a workable solution:

Here is what I did

$url= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

if ($url=='mysite.com/')
echo "Introduction";

reference:
http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Windows/Q_20920683.html

Thanks for everyone's help though, it was instrumental in helping me find the solution. Thanks.
0
 

Author Comment

by:frogpad
ID: 17015945
I think normally your solutions would have worked, it's just that I have a few quirks in my CMS. Points assigned accordingly. Thanks again.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now