Jump to content

links, current page


UnknownPlayer

Recommended Posts

Why this code dont work :S

<?php
    echo '
    <ul>
        <li'; if ($_SERVER['PHP_SELF'] == "kategorije.php") { echo ' id="current"'; } echo '><a href="kategorije.php"><span>Kategorije</span></a></li>
    </ul>';
?>

 

Checking if PHP_SELF is "kategorije.php" do not work, why, and what is solution ?

Link to comment
https://forums.phpfreaks.com/topic/213328-links-current-page/
Share on other sites

Why this code dont work :S

<?php
    echo '
    <ul>
        <li'; if ($_SERVER['PHP_SELF'] == "kategorije.php") { echo ' id="current"'; } echo '><a href="kategorije.php"><span>Kategorije</span></a></li>
    </ul>';
?>

 

Checking if PHP_SELF is "kategorije.php" do not work, why, and what is solution ?

 

It doesn't work because PHP_SELF contains the path aswell as the filename, e.g. /my/path/kategorije.php

 

use basename() to remove the path and it will work, like this

 

if(basename($_SERVER['PHP_SELF']) == 'kategorije.php')
{
// do something
}

Link to comment
https://forums.phpfreaks.com/topic/213328-links-current-page/#findComment-1110867
Share on other sites

Why this code dont work :S

<?php
    echo '
    <ul>
        <li'; if ($_SERVER['PHP_SELF'] == "kategorije.php") { echo ' id="current"'; } echo '><a href="kategorije.php"><span>Kategorije</span></a></li>
    </ul>';
?>

 

Checking if PHP_SELF is "kategorije.php" do not work, why, and what is solution ?

 

It doesn't work because PHP_SELF contains the path aswell as the filename, e.g. /my/path/kategorije.php

 

use basename() to remove the path and it will work, like this

 

if(basename($_SERVER['PHP_SELF']) == 'kategorije.php')
{
// do something
}

Thanks it works this way.

I thought $_SERVER['PHP_SELF'] is file name.. :S

Link to comment
https://forums.phpfreaks.com/topic/213328-links-current-page/#findComment-1111066
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.