Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Only Show Paragraph for Specific URL

Posted on 2006-06-29
9
Medium Priority
?
305 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 120 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 80 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

971 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