DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   $_server['script_name'] (http://www.daniweb.com/forums/thread123384.html)

phploveisgood May 9th, 2008 9:52 am
$_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

buddylee17 May 9th, 2008 10:56 am
Re: $_server['script_name']
 
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'];
?>

phploveisgood May 9th, 2008 11:49 am
Re: $_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.

jstorz May 10th, 2008 1:57 pm
Re: $_server['script_name']
 
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.

Quote:

Originally Posted by phploveisgood (Post 603611)
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 May 10th, 2008 2:57 pm
Re: $_server['script_name']
 
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.

buddylee17 May 10th, 2008 5:17 pm
Re: $_server['script_name']
 
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"';
}
?>

amigura May 11th, 2008 8:13 am
Re: $_server['script_name']
 
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'];

phploveisgood May 11th, 2008 2:51 pm
Re: $_server['script_name']
 
I have tried the code, but did not work.

Regards

amigura May 11th, 2008 3:31 pm
Re: $_server['script_name']
 
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"';
}

jstorz May 11th, 2008 3:49 pm
Re: $_server['script_name']
 
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/ ]]


All times are GMT -4. The time now is 3:14 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC