Page 1 of 1

PHP Code For hiding a button

Posted: Wed Nov 30, 2011 11:56 pm
by php_itdeveloper
Hi to all,

I am new php programmer. And, i need a solution for this option.

I have a website, where there are several Top Menus.
On the Home Menu, i included a buttonm, say "My-Button". And, i want this button to be shown on this home index page only.
This button should not show up on the other page, where it is under other Top Menu.

Eg: Suppose mydomain.com is my website.

It has Home, About Us, Contact Us (say)
Under Home, there are other left side menu, say "Home1", "Home2", "Home3".
This Home1, Home2 , Home3 page should have this button "My-Button"

Under About Us, there are other left side menu, say "About Us1", "About Us2", "About Us3".
Same for Contact Us also, like Contact Us1, Contact Us2, Contact Us3

This About Us1, About Us2 , About Us3, Contact Us1, Contact Us2, Contact Us3 page should not have this button "My-Button"


And, let say page name are like
For Home, it is http://www.my-domain.com
under this, say for Home1 url as http://www.my-domain.com/home1, Home2 url as http://www.my-domain.com/home2, Home3 url as http://www.my-domain.com/home3

For About Us, say http://www.my-domain.com/about-us
under this, say for About Us1 url as http://www.my-domain.com/About Us1, About Us2 url as http://www.my-domain.com/About Us2, About Us3 url as http://www.my-domain.com/About Us3

For Contact Us, say http://www.my-domain.com/contact-us
under this, say for Contact Us1 url as http://www.my-domain.com/Contact Us1, Contact Us2 url as http://www.my-domain.com/Contact Us2, Contact Us3 url as http://www.my-domain.com/Contact Us3

So, my question is, can we hide this button "My-Button" using the page-name in these pages About Us1, About Us2, About Us3, Contact Us1, Contact Us2, Contact Us3 ?

Any help are welcome and appreciate for your help.

Re: PHP Code For hiding a button

Posted: Thu Dec 01, 2011 4:54 am
by mikeashfield
Forgive me if I'm wrong, but I think you're after something like the code below, say for example you're on about_me.php then the script will generate 3 links for about_me_1.php, about_me_2.php and about_me_3.php

Code: Select all

<?php
//Function that gets the current page URL
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 //The output from the funtion is $pageURL
 return $pageURL;
}
//This strips the URL down to the current page filename (example: index.php)          
$URLpieces=explode('.', basename(curPageURL()));
//Get rid of the file extention and replaces all underscores with whitespaces (also Camel Cases All Words.)
$pageTitle=ucwords(strtolower(str_replace('_',' ',$URLpieces[0])));

for ($i=1; $i<4; $i++) {
echo "<a href='"."http://www.mydomain.com/".
str_replace(' ','_',$pageTitle).$i.".php'>".
$pageTitle." ".$i.
"</a><br />";
}
?>