php - Having trouble with includes and relative paths -
i'm building out small page live duration of 5 day conference. each day site needs load new content i'm using small script load in include file. i'm trying includes relative paths isn't working right. below current code i'm working uses array (24 today's date check see if ti working) dates maps file , default piece of content should conditional not return result.
<?php $path = $_server['http_host']; $date = date("j"); $event_dates = array(24,15,16,17,18,19); if (in_array($date, $event_dates)) { $path .= "/_includes/date-".$date.".php"; include($path); } else { $path .= "/_includes/default.php"; include($path); } ?>
if include "_includes/default.php", works fine , might need solution i'd figure out relative path problem same in case run same issue @ later date. also, if change include echo result expect.
since you're using .=
, "/_includes/..."
string concatenated $path
. have of form localhost/_includes/...
. not contain scheme (http(s)), work if have folder localhost
in directory.
if want current directory, use dirname(__file__)
instead. use ./_includes/...
path if _includes
subdirectory of current directory, etc.
Comments
Post a Comment