0

So i made a global.php but on the header i am trying to make it go in between the pages so i can edit it easier so i am using that file but i have it highlight the page on the header you are on so how can i get the link so i can take out the parts?

Here is what i mean:

I have http://16austin16.chalkcraftserver.xyz/Downloads/

And i want to take out most of it to make it just Downloads to make it highlight the page on the header

sKhan
  • 9,694
  • 16
  • 55
  • 53
16austin16
  • 17
  • 9

2 Answers2

1

The quickest way would be to use 'parse_url()'

Example:

$url_parts = parse_url("http://16austin16.chalkcraftserver.xyz/Downloads/");
var_dump($url_parts); // Just showing what parse_url produces
var_dump($url_parts['path']); // Produces string(11) "/Downloads/"

$simple_name = trim($url_parts['path'], '/');
echo $simple_name; // Downloads

Check out https://secure.php.net/manual/en/function.parse-url.php

Hiphop03199
  • 729
  • 3
  • 16
  • i was also wondering is there a way to get the url instead of hard coding it in because i was planning to do this in the global file – 16austin16 Feb 12 '16 at 00:59
  • Sure, try "$currentPage = $_SERVER['REQUEST_URI'];" And then substitute $currentPage in for the URL I used in the answer. – Hiphop03199 Feb 12 '16 at 01:03
  • now i cant figure out how to include the file that has the stuff because idk how to get out of the downloads folder to access global.php – 16austin16 Feb 12 '16 at 01:24
  • 'the file that has the stuff' and 'get out of the downloads folder to access global.php' is a little to vague for me to understand without deeper understanding of your program. – Hiphop03199 Feb 12 '16 at 01:28
  • so i am trying to do `include("global.php");` that but the global.php isnt in my downloads so i dont know how to access it with include – 16austin16 Feb 12 '16 at 01:30
  • Have you tried 'include("../global.php");'? Adding as many '../'s as necessary to go up a directory each time. – Hiphop03199 Feb 12 '16 at 01:41
  • ok thanks i might modify some stuff – 16austin16 Feb 12 '16 at 01:50
0

Use:

$page = basename(dirname(__FILE__));

Then you can perform code specific to the page:

if($page == 'Downloads'){
  //do code here
}

Or you can print a class to the header element that denotes the page, something similar to:

echo "<header>";
echo "<a href='Downloads'".($page == 'Downloads'?" class='current'":"").">Downloads</a>";
echo "</header>";

The important part of the above three lines being ($page == 'Downloads'?" class='current'":""). It's a concise if statement that in pseudocode reads if the current page is 'Downloads', then print the 'current' class to the anchor, otherwise print nothing.