Solved

Only Show Paragraph for Specific URL

Posted on 2006-06-29
9
298 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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