?> $_server['script_name'] - Page 2 - PHP
User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,011 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,768 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 793 | Replies: 19
Reply
Join Date: Apr 2008
Posts: 9
Reputation: phploveisgood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phploveisgood phploveisgood is offline Offline
Newbie Poster

Re: $_server['script_name']

  #11  
May 11th, 2008
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
Reply With Quote  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: $_server['script_name']

  #12  
May 15th, 2008
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?
Reply With Quote  
Join Date: May 2008
Posts: 31
Reputation: rgviza is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
rgviza rgviza is offline Offline
Light Poster

Re: $_server['script_name']

  #13  
May 15th, 2008
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
Reply With Quote  
Join Date: Apr 2008
Posts: 9
Reputation: phploveisgood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phploveisgood phploveisgood is offline Offline
Newbie Poster

Re: $_server['script_name']

  #14  
May 15th, 2008
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:

  1. <!-- Navigation item -->
  2. <?php
  3.  
  4. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
  5. if ($bobo)
  6. {
  7. $style_home = 'style="background-color: #6C674F"';
  8. }
  9.  
  10. ?>
  11. <ul>
  12.  
  13. <li class="linkLevel01">
  14. <a href="index.php" class="homy"<?php echo $style_home ?>>Home</a>
  15. </li>
  16. </li>
  17.  
  18. <li class="linkLevel01">
  19. <a href="kamine.php?page=1" class="homy">Kamine</a>
  20. </li>
  21.  
  22. <!-- Navigation item -->
  23.  
  24. <li class="linkLevel01">
  25. <a href="#" class="homy">Accessoires<!--[if IE 7]><!--></a>
  26. <!--<![endif]-->
  27. <!--[if lte IE 6]><table><tr><td><![endif]-->
  28. <ul class="dropdown">
  29. <div class="dropdownMob">
  30. <li><a href="kaminkoerbe.php">
  31. <h6 class="ontok">Kamink&ouml;rbe</h6></a></li>
  32. <li><a href="kamineinsaetze.php">
  33. <h6 class="ontok">Kamineins&auml;tze</h6></a></li>
  34. <li><a href="kaminvorsaetze.php">
  35. <h6 class="ontok">Kaminvors&auml;tze</h6></a></li>
  36. </div>
  37. </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
  38. </li>
Last edited by peter_budo : May 16th, 2008 at 5:58 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: May 2008
Posts: 31
Reputation: rgviza is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
rgviza rgviza is offline Offline
Light Poster

Re: $_server['script_name']

  #15  
May 15th, 2008
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=
Reply With Quote  
Join Date: Apr 2008
Posts: 9
Reputation: phploveisgood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phploveisgood phploveisgood is offline Offline
Newbie Poster

Re: $_server['script_name']

  #16  
May 15th, 2008
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.


  1. <?php
  2.  
  3. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
  4. if ($bobo)
  5. {
  6. $style_home = 'style= "background-color: #6C674F"';
  7. }
  8.  
  9.  
  10. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kanim.php");
  11. if ($bobo)
  12. {
  13. $style_home = 'style= "background-color: #6C674F"';
  14. }
  15.  
  16. ?>
  17. <ul>
  18.  
  19. <li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home ?>>Home</a></li>
  20. </li>
  21.  
  22. <li class="linkLevel01"><a href="kamine.php?page=1" class="homy"<?php echo $style_home ?>>Kamine</a></li>
Last edited by peter_budo : May 16th, 2008 at 5:59 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: $_server['script_name']

  #17  
May 15th, 2008
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.
Last edited by amigura : May 15th, 2008 at 5:03 pm.
Reply With Quote  
Join Date: Apr 2008
Posts: 9
Reputation: phploveisgood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phploveisgood phploveisgood is offline Offline
Newbie Poster

Re: $_server['script_name']

  #18  
May 16th, 2008
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.

  1. <!-- Navigation item -->
  2. <?php
  3.  
  4. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
  5. if ($bobo)
  6. {
  7. $style_home = ' style="background-color: #6C674F"';
  8. }
  9. ?>
  10.  
  11. <?php
  12. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kamine.php?page=1");
  13. if ($bobo)
  14. {
  15. $style_kamine = ' style="background-color: #6C674F"';
  16. }
  17.  
  18. ?>
  19. <ul>
  20.  
  21. <li class="linkLevel01">
  22. <a href="index.php" class="homy"<?php echo $style_home?> exit;>Home</a>
  23. </li>
  24. </li>
  25.  
  26. <li class="linkLevel01">
  27. <a href="kamine.php?page=1" class="homy"<?php echo $style_kamine?>>Kamine</a>
  28. </li>
Last edited by peter_budo : May 16th, 2008 at 6:01 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Apr 2008
Posts: 9
Reputation: phploveisgood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phploveisgood phploveisgood is offline Offline
Newbie Poster

Re: $_server['script_name']

  #19  
May 16th, 2008
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.

  1. <!-- Navigation item -->
  2. <?php
  3.  
  4. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/index.php");
  5. if ($bobo)
  6. {
  7. $style_home = ' style="background-color: #6C674F"';
  8. }
  9. ?>
  10.  
  11.  
  12. <?php
  13. $bobo = strrpos($_SERVER['SCRIPT_FILENAME'], "/bobo/kamine.php?page=1");
  14. if ($bobo)
  15. {
  16. $style_kamine = ' style="background-color: #6C674F"';
  17. }
  18.  
  19. ?>
  20. <ul>
  21.  
  22.  
  23. <li class="linkLevel01"><a href="index.php" class="homy"<?php echo $style_home?>>Home</a></li>
  24. </li>
  25.  
  26.  
  27.  
  28. <li class="linkLevel01"><a href="kamine.php?page=1" class="homy"<?php echo $style_kamine?>>Kamine</a></li>
Last edited by peter_budo : May 16th, 2008 at 6:01 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: $_server['script_name']

  #20  
May 16th, 2008
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>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 10:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC