Debt Consolidation - Find jobs - Wordpress Themes - iPhone Store - Air Jordan Release Date

PDA

View Full Version : include file based on url


jazzylee77
Nov 8th 2007, 7:48 pm
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");
}
?>

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.

phper
Nov 8th 2007, 7:59 pm
The equal sign should be a double equal sign:
if (curPageURL() == "http://www.mysite.com/tag/Sports")

jazzylee77
Nov 8th 2007, 8:24 pm
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");
}
?>

phper
Nov 8th 2007, 8:51 pm
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.

jazzylee77
Nov 8th 2007, 9:00 pm
Ah! Good eye! That was it. I had copied part of it from another file and the odd character sneaked in. Thanks.

jazzylee77
Nov 8th 2007, 9:03 pm
Ok now I could repeat that if else for all the different categories and sub menus. But maybe there is a more efficient way.

jazzylee77
Nov 9th 2007, 6:11 am
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");


but also including sports.php for http://www.mysite.com/tag/Sports/Baseball http://www.mysite.com/tag/Sports/Baseball/Bats etc.

jazzylee77
Nov 9th 2007, 7:25 am
Ok I found that. Just change == to >=

fun to watch me learn huh? ;)