954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

$_server['script_name']

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

phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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'];
?>
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
 

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.

phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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['SCRIPT_NAME'] ; 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['SCRIPT_NAME'] == '/bobo/index.php')
{
$style_home = 'style="background-color: #6C674F"';
}
?>
>Home

What would you have done to make it work.

jstorz
Newbie Poster
6 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

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.

phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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

<?php
if($_SERVER['SCRIPT_NAME'] == 'index.php')
{
$style_home = 'style="background-color: #6C674F"';
}
?>
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
 

comparing $_SERVER['SCRIPT_NAME'] == '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'];
amigura
Junior Poster in Training
72 posts since Jan 2008
Reputation Points: 11
Solved Threads: 7
 

I have tried the code, but did not work.

Regards

phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

hmm for both $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF'] 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"';
}
amigura
Junior Poster in Training
72 posts since Jan 2008
Reputation Points: 11
Solved Threads: 7
 

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 [[ www.bobo.domain.com ]] instead of [[ www.domain.com/bobo/ ]]

jstorz
Newbie Poster
6 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

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

phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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?

amigura
Junior Poster in Training
72 posts since Jan 2008
Reputation Points: 11
Solved Threads: 7
 

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

rgviza
Light Poster
31 posts since May 2008
Reputation Points: 18
Solved Threads: 5
 

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>
phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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=

rgviza
Light Poster
31 posts since May 2008
Reputation Points: 18
Solved Threads: 5
 

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>
phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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.

amigura
Junior Poster in Training
72 posts since Jan 2008
Reputation Points: 11
Solved Threads: 7
 

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>
phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

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>
phploveisgood
Newbie Poster
14 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

the original code works ok apart from missing ;
u should use code tags [CODE ] code here [/CODE ]

<!-- 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>
amigura
Junior Poster in Training
72 posts since Jan 2008
Reputation Points: 11
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You