Aria-current="page" not working

Hi, sorry for my English…

I have a PHP file for changing my pages, the Code is this,

<?php
class NavigationLinkList {     
	private $current_page;
	private $arLinks;
    
	public function __construct( $arNewLinks = false ) {
		$this -> arLinks = []; 
		$this -> addLinks ( $arNewLinks  );
		$this -> current_page = $_SERVER['REQUEST_URI'];
	}
     
	public function addLinks ( $arNewLinks ) {
		$flagErrors = false;
		if ( isset( $arNewLinks['URL'] ) && isset( $arNewLinks['TEXT'] ) ) {  #Auf diesen if ,baut der array ...   
			array_push( $this -> arLinks, $arNewLinks );
			return true;
		}
		if ( is_array ( $arNewLinks ) ) {
			foreach ( $arNewLinks as $NewLink ) {
				if ( isset( $NewLink['URL'] ) && isset( $NewLink['TEXT'] ) ) {
					array_push( $this -> arLinks, $NewLink );
				}               
			}
		} else {
			$flagErrors = true;
		}
		return false == $flagErrors;
	}


	public function printNav() {
		echo '
		<form class="link_change">
			<ul>' .  PHP_EOL;
        
		foreach ( $this -> arLinks as $link ) {
			if ( $this -> current_page == $link['URL'] ) {
				$aria = ' aria-current="page"';
			} else {
				$aria = '';
			}
			echo '				<li><a' . $aria . ' href=' . $link['URL'] .'>' . $link['TEXT'] . '</a></li>' . PHP_EOL;
		}
        
		echo '
			</ul>
		</form>' .  PHP_EOL;
	}
}




$_SERVER['REQUEST_URI'];



$navListe = new NavigationLinkList();
$navListe -> addLinks( [ 'URL' => 'index.php', 'TEXT' => '1' ] );
$navListe -> addLinks( [ 'URL' => 'index2.php', 'TEXT' => '2' ] );
$navListe -> printNav();

I have a File CSS for page change,

.link_change ul {

    list-style-type: none;
     margin-left: 340px;
   

}

 

.link_change li {

  display: inline;

}

 

.link_change a {

   display: inline;

   text-decoration: none;

   border: 1px solid gray;

   background-color: #FE2E64;

   color: black;

   padding: 8px;

   opacity: 0.5;

   font-family: Times New Roman;

}

 

.link_change a:hover {

   background-color: #9f9e9e;

}

 


.link_change a[aria-current="page"] {

   background-color: green;
}

All working gut, how the Screenshot to show,
5

my Problem is with


.link_change a[aria-current="page"] 

it will not to change the Color…

Can please someone help me to solve this problem, Thanks!

Did you try inspecting via browser dev tools?

Note the leading ‘/’ in REQUEST_URI. However the ‘URL’ => ‘index.php’ does not have a leading ‘/’.

For some reason I can’t use links? Why freeCodeCamp? //www .php .net/ manual/en/reserved.variables.server.php

@ aesyondu, Thanks for your answer!, but people help me with the solution…

The solution:

In every Page were I to want to change my page, top above, build a Variable and give it a value,

<?php
$currentes_pages = "1";

in every Page change the value, on Page 2, write,

<?php
$currentes_pages = "2";

later, below where build the Links, for connect both Sites, write,

<ul class="link_change">
   <li id="pages">Pages</li>
   <li><a <?php if ($currentes_pages=="1"): ?>aria-current="page" <?php endif ?> href="/index.php">1</a></li>
   <li><a <?php if ($currentes_pages=="2"): ?>aria-current="page" <?php endif ?> href="/index2.php">2</a></li>
</ul>