mishasoni Posted March 24, 2009 Share Posted March 24, 2009 Hello! I am somewhat new to php and am hoping someone can help me out with a problem. I have a php page with a php include file that contains javascript. The javascript is for a stylized sort menu that sorts the current results on the parent page. Therefore, I need to get the full url (including url variables) of the parent file from within a js script in the include file. So far this is what I have, but it doesn't work ($pageURL is empty when looking at the page source): parent file: <?php // get the full page url $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"]; } ?> . . . <?php include("include.php"); ?> include file: <script type="text/javascript"> //Contents for a sort menu that sorts the current results on the parent page menu1[0]='<a href="<?php echo($pageURL);?>&sort=yearDESC">Year: descending</a>' menu1[1]='<a href="<?php echo($pageURL);?>&sort=yearASC">Year: ascending</a>' menu1[2]='<a href="<?php echo($pageURL);?>&sort=title">Title: A-Z</a>' Maybe there is a better way to do this? Any help would be mush appreciated. Link to comment https://forums.phpfreaks.com/topic/150813-get-full-url-of-parent-page-from-include-file/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.