Solved

Only Show Paragraph for Specific URL

Posted on 2006-06-29
9
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

636 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