I'm wanting to show a different submenu file for different folders of a dynamic script. This is what I have so far, but doesn't work. <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <?php echo curPageURL(); ?> <?php if (curPageURL() = “http://www.mysite.com/tag/Sports") { include("Sports.php"); } else { include("default.php"); } ?> PHP: I had the echo curPageURL(); part in there just to test that it was getting pageurl ok and it worked till I added the bit afterward.
The equal sign should be a double equal sign: if (curPageURL() == "http://www.mysite.com/tag/Sports")
I wasn't sure about the equal operator and had tried the double equal as well. So I've made that change back to the ==. Still doesn't work current code (other than mysite.com) <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <?php echo curPageURL(); ?> <?php if (curPageURL() == “http://www.mysite.com/tag/Sports") { include("test.php"); } else { include("default.php"); } ?> PHP:
The opening quote looks funny there. Just a wild guess, are you using MS Word to code? If so, open the file with Notepad and re-type the quote mark in the same line above (the one that enclosed http://www.mysite.com/tag/Sports). Otherwise, pasting the error messages that you get to here will help investigating the issue.
Ah! Good eye! That was it. I had copied part of it from another file and the odd character sneaked in. Thanks.
Ok now I could repeat that if else for all the different categories and sub menus. But maybe there is a more efficient way.
using elseif this is working fine. Now how do I make the include work for subfolders too? if (curPageURL() == “http://www.mysite.com/tag/Sports") { include("sports.php"); PHP: but also including sports.php for http://www.mysite.com/tag/Sports/Baseball http://www.mysite.com/tag/Sports/Baseball/Bats etc.