Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.