tags:

views:

26

answers:

4

May i know how set active menu which page something like page.php?name=about

$a = basename($_SERVER['SCRIPT_NAME']);

<li<?php if ($a == 'page.php?name=about'){?> class="active"<?php }?>><a href="<?php echo $url; ?>/page.php?name=about" title="About">About</a></li>

My class won't active while on page.php?name=about

May I know how to fix it?

A: 

you're looking for:

$_GET['name']

The $_GET superglobal is how you access variables from the query string.

$class = ($_GET['name'] == 'about' ? "active" : "");
echo "<li class=\"$class\">";
Fosco
thanks Fosco.. I got two options here. BTW $_GET['name'] is required to sanitize?
delicious
If you're not using it in a database query, I don't see why you would sanitize it.
Fosco
A: 

Change the if condition to: if ($a == 'page.php' && $_GET['name'] == 'about')

dragosplesca
A: 

$_SERVER['SCRIPT_NAME'] only gives you the name of the script. The parameters aren't included. You need to use the $_GET array to get parameters (or $_POST if they came that way). Try this:

<li<?php if ($_GET['name'] == 'about'){?> class="active"<?php }?>><a href="<?php echo $url; ?>/page.php?name=about" title="About">About</a></li>
Cfreak
A: 

Your $a definition would need to be as follows to work as you intend

$a = $_SERVER['SCRIPT_NAME'].'?name='.$_GET['name'];
<li<?php if ($a == '/page.php?name=about'){?> class="active"<?php }?>><a href="<?php echo $url; ?>/page.php?name=about" title="About">About</a></li>

Alternatively, you can just use

if ($_SERVER['SCRIPT_NAME']=='/page.php')
    $a=$_GET['name'];

<li<?php if ($a == 'about'){?> class="active"<?php }?>><a href="<?php echo $url; ?>/page.php?name=about" title="About">About</a></li>
Robert