wkilc Posted July 21, 2008 Share Posted July 21, 2008 Hello, I am trying to "grab" an entire URL, which may include queries: $page_name = $_SERVER["REQUEST_URI"]; I'm using the URL, amongst other things, for paging (letting the user decide how many records per page): <a href='<? echo "$page_name" ?>&limit=25'>25 records per page</a> <a href='<? echo "$page_name" ?>&limit=50'>50 records per page</a> This works okay... If the page was "index.php?car=honda"... clicking the first link will give me this: index.php?car=honda&limit=25 Now click on the next link and I get: index.php?car=honda&limit=25&limit=50 I understand why (because I'm trapping the whole previous URL), and the code works, but it's very ugly. How can I write it so that the entire URL is trapped, save for the new "limit", which will be overwritten, rather than tacked on the end? Thanks. ~Wayne Link to comment https://forums.phpfreaks.com/topic/115922-solved-_serverquotrequest_uriquot/ Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 try <?php $page_name = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; ?> <a href='<? echo $page_name ?>&limit=25'>25 records per page</a> EDIT: i made a dumb mistake! Link to comment https://forums.phpfreaks.com/topic/115922-solved-_serverquotrequest_uriquot/#findComment-596000 Share on other sites More sharing options...
kenrbnsn Posted July 21, 2008 Share Posted July 21, 2008 Instead of doing it that way, just rebuild it from the $_GET array: <?php $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $page_name = $_SERVER['SCRIPT_NAME'] . '?' . implode('&',$tmp); ?> MadTechie: your solution has the same problem as the OP's. Ken Link to comment https://forums.phpfreaks.com/topic/115922-solved-_serverquotrequest_uriquot/#findComment-596002 Share on other sites More sharing options...
wkilc Posted July 21, 2008 Author Share Posted July 21, 2008 Man I wish I could think like that... THANK YOU!! ~Wayne Link to comment https://forums.phpfreaks.com/topic/115922-solved-_serverquotrequest_uriquot/#findComment-596010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.