Solved

Only Show Paragraph for Specific URL

Posted on 2006-06-29
9
296 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

821 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