Please I need some help!

When I am developing, these code below works fine:

<?php 
if($_SERVER['SCRIPT_NAME'] == '/aktuelle seite/index.php')
{
	$style_home = 'style="background-color: #6C674F"';
}	
?>
<ul> 
            
<li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home ?>>Home</a></li>

But, when I put on the server :

<?php 
if($_SERVER['SCRIPT_NAME'] == '/bobo/index.php') 
//"bobo" is the name of the folder on my server]
{
	$style_home = 'style="background-color: #6C674F"';
}	
?>
<ul> 
            
<li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home ?>>Home</a></li>

It won't work.

Please help me out.

Best regards

Max

echo or print the variable to see what it actually is.

<?php
if($_SERVER['SCRIPT_NAME'] == '/bobo/index.php') {
$style_home = 'style="background-color: #6C674F"';
} 
echo $_SERVER['SCRIPT_NAME'];
?>

Excuse me! I don't realy understand what you mean. These are my code:

<?php
if($_SERVER['SCRIPT_NAME'] == '/bobo/index.php')
{
$style_home = 'style="background-color: #6C674F"';
}
?>
<ul>


<li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home ?>>Home</a></li>

What would you have done to make it work.

try this,

if (preg_match("/bobo\/index.php/i",$_SERVER['REQUEST_URI'])) {
  $style_home = 'style="background-color: #6C674F"';
}

instead of

if($_SERVER['SCRIPT_NAME'] == '/bobo/index.php')
{
$style_home = 'style="background-color: #6C674F"';
}

or like was said above just echo $_SERVER ; to see what the variable actually is and adjust from there.

Excuse me! I don't realy understand what you mean. These are my code:

<?php
if($_SERVER == '/bobo/index.php')
{
$style_home = 'style="background-color: #6C674F"';
}
?>
<ul>


<li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home ?>>Home</a></li>

What would you have done to make it work.

I have tried the code you send to me, but it did not work.

And when I tried the first code you sent:

<?php
if($_SERVER['SCRIPT_NAME'] == '/bobo/index.php') 
{
   $style_home = 'style="background-color: #6C674F"';
}
echo $_SERVER['SCRIPT_NAME'];
?>

It only eched the word "index.php", not the style.

Thanks one more time for efforts. Please I am open for more helps

Best regards.

Okay, that means that $_SERVER equals index.php. Therefore, compare the current page($_SERVER) to index.php:

<?php
if($_SERVER['SCRIPT_NAME'] == 'index.php')
{
$style_home = 'style="background-color: #6C674F"';
}
?>

comparing $_SERVER == 'index.php' will not work for you as /bobo/index.php' and '/aktuelle seite/index.php' will give same style.

try below to see wat you get

echo $_SERVER['PHP_SELF'];

hmm for both $_SERVER and $_SERVER not to work you might have a problem with your php.

$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
if ($bobo) 
{
$style_home = 'style="background-color: #6C674F"';
}

or

if ($_SERVER['REQUEST_URI']=="/bobo/index.php") 
{
$style_home = 'style="background-color: #6C674F"';
}

Perhaps we are not hearing the whole story. Would "bobo" happen to be a subdomain instead of a subfolder? This would cause script_name and all the rest to just spit out index.php.

So is it? a subdomain would look like this [[ [url]www.bobo.domain.com[/url] ]] instead of [[ [url]www.domain.com/bobo/[/url] ]]

Thanks alot! It works! But only on the "Home link". I tried to put t on "About us, News etc. links" by using ELSEIF, it did not work. Regards

ok did u change index.php to other file names. u didn't say which one was working so i choose this. it will work on all files in bobo folder.

but i will also say that any folder combination will set it off also e.g.

folder/bobo/newfolder/
bobo/folder/newfolder/
folder/bobo/bobo/

$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/");
if ($bobo) 
{
$style_home = 'style="background-color: #6C674F"';
}

i don't know how you got it setup but you could think about a include config style file
wat does $style_home do?

I'm actually surprised this works at all anywhere because the result will look like:

<li class="linkLevel01"><a href="index.php" class="homy"style="background-color: #6C674F">Home</a></li>

when printed to the page. You need a space before style=

so you end up with:

<li class="linkLevel01">
-------------------------------| |-----------
<a href="index.php" class="homy" style="background-color:#6C674F">Home</a>
</li>

If the browser parses attributes correctly it won't see the style at all as it is.

You can almost always sanity check whether it's a php problem or html by echoing "Made it to here" or something within the conditional logic:

#
if($_SERVER['SCRIPT_NAME'] == 'index.php')
#
{
#
//sanity check
echo "Made it to here";exit;
$style_home = 'style="background-color: #6C674F"';
#
}

if it prints the test and the script exits, php is fine.

-r

Hallo, thanks again. The $style_home gives the active link another color, to specify the user which page he is viewing. This is part of the code:

<!-- Navigation item -->
<?php 
		  
$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
if ($bobo) 
{
    $style_home = 'style="background-color: #6C674F"';
}
	
?>
<ul>
		  
<li class="linkLevel01">
<a href="index.php" class="homy"<?php echo $style_home ?>>Home</a>
</li>
</li>
          
<li class="linkLevel01">
<a href="kamine.php?page=1" class="homy">Kamine</a>
</li>
          
<!-- Navigation item -->
              
<li class="linkLevel01">
<a href="#" class="homy">Accessoires<!--[if IE 7]><!--></a>
<!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]-->
    <ul class="dropdown">
        <div class="dropdownMob">
            <li><a href="kaminkoerbe.php">
            <h6 class="ontok">Kamink&ouml;rbe</h6></a></li>
            <li><a href="kamineinsaetze.php">
            <h6 class="ontok">Kamineins&auml;tze</h6></a></li>
            <li><a href="kaminvorsaetze.php">
            <h6 class="ontok">Kaminvors&auml;tze</h6></a></li>
	</div>
   </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>

there's still no space between the attributes.
try

$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
if ($bobo)
{
$style_home = ' style="background-color: #6C674F"';

you need a space in front of style=

It works fine on index.php. But when trying it on kamin.php, the style will appear on both links. Bobo is the folder on the sever and in this folder is all my php files.

<?php

$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
if ($bobo)
{
  $style_home = 'style= "background-color: #6C674F"';
}


$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kanim.php");
if ($bobo)
{
  $style_home = 'style= "background-color: #6C674F"';
}

?>
<ul>

<li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home ?>>Home</a></li>
</li>

<li class="linkLevel01"><a href="kamine.php?page=1" class="homy"<?php echo $style_home ?>>Kamine</a></li>

it is because u have $style_home on all links therefore when $style_home is active for one link it will do it for all links. do $style_home1 $style_home2 or something

there's still no space between the attributes.

i tried no space thing and it works. i'm guessing due to " " closing var before it.

When I code it this way, the styling will display on both links at thesame time. And I want it one at a time. That is, when on index.php, show style and when kamin.php, show style.

<!-- Navigation item -->
<?php 
		  
$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
if ($bobo) 
{
   $style_home = ' style="background-color: #6C674F"';
}
?> 
         
<?php 	
$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kamine.php?page=1");
if ($bobo) 
{
    $style_kamine = ' style="background-color: #6C674F"';
}
	
?>          
<ul>
		  
    <li class="linkLevel01">
    <a href="index.php" class="homy"<?php echo $style_home?> exit;>Home</a>
    </li>
    </li>
          
    <li class="linkLevel01">
    <a href="kamine.php?page=1" class="homy"<?php echo $style_kamine?>>Kamine</a>
    </li>

When I code it this way, the styling will display on both links at thesame time. And I want it one at a time. That is, when on index.php, show style and when kamin.php, show style.

<!-- Navigation item -->
<?php

$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
if ($bobo)
{
$style_home = ' style="background-color: #6C674F"';
}
?>


<?php
$bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kamine.php?page=1");
if ($bobo)
{
$style_kamine = ' style="background-color: #6C674F"';
}

?>
<ul>


<li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home?>>Home</a></li>
</li>



<li class="linkLevel01"><a href="kamine.php?page=1" class="homy"<?php echo $style_kamine?>>Kamine</a></li>

the original code works ok apart from missing ;
u should use code tags code here

<!-- Navigation item -->
<?php

if (strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php"))
{
$style_home = 'style="background-color: #6C674F"';
}
elseif (strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kamine.php"))
{
$style_kamine = 'style="background-color: #6C674F"';
}

?>
<ul>

<li class="linkLevel01"><a href="index.php" class="homy" <?php echo $style_home; ?>>Home</a></li>

<li class="linkLevel01"><a href="kamine.php?page=1" class="homy" <?php echo $style_kamine; ?>>Kamine</a></li>

</ul>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.