Jump to content

[SOLVED] $_SERVER["REQUEST_URI"]


wkilc

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.