wkilc Posted August 19, 2010 Share Posted August 19, 2010 I'm a noob, tring to reverse engineer some current code. This code is grabbing the current URL: <?php function curPageURL() { $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"]; } return $pageURL; } ?> This form is adding "&limit=50" to the URL, to show 25, 50 or 100 results per page: <form> <select name="link"> <option <? echo "$select25" ?> value="<? echo curPageURL(); ?>&limit=25">25 records per page</option> <option <? echo "$select50" ?> value="<? echo curPageURL(); ?>&limit=50">50 records per page</option> <option <? echo "$select100" ?> value="<? echo curPageURL(); ?>&limit=100">100 records per page</option> </select> </form> The problem is here (I think). This is supposed to flush the old limit before requesting a new one... but right now, I'm getting another one tacked on with each new request: www.website.com/members?sub[]=math&sub[]=science&lev[]=middleschool&limit=25 www.website.com/members?sub[]=math&sub[]=science&lev[]=middleschool&limit=25&limit=50 www.website.com/members?sub[]=math&sub[]=science&lev[]=middleschool&limit=25&limit=50&limit=100 <?php //remove any old limit from query $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '?' . implode('&',$tmp); ?> Any ideas? Thanks. ~Wayne Quote Link to comment Share on other sites More sharing options...
jodietle Posted August 19, 2010 Share Posted August 19, 2010 You probably could locate the first instance of "&limit" in the URL, determine the position via the stripos() function and pull everything before that. Quote Link to comment Share on other sites More sharing options...
jodietle Posted August 19, 2010 Share Posted August 19, 2010 There's also the stristr function which you can locate the first occurence of "&limit=" and pull everything before that using one function and putting true as the third param. Here's an example from php.net (http://www.php.net/manual/en/function.stristr.php) <?php $email = 'USER@EXAMPLE.com'; echo stristr($email, 'e'); // outputs ER@EXAMPLE.com echo stristr($email, 'e', true); // As of PHP 5.3.0, outputs US ?> Quote Link to comment Share on other sites More sharing options...
wkilc Posted August 19, 2010 Author Share Posted August 19, 2010 Thank you. Again, I'm pretty green... <?php $curPageURL = $curPageURL; echo stristr($curPageURL, '&limit='); // outputs ER@EXAMPLE.com echo stristr($curPageURL, '&limit=', true); // As of PHP 5.3.0, outputs US ?> gives me: Warning: Wrong parameter count for stristr() Thanks. ~Wayne Quote Link to comment Share on other sites More sharing options...
wkilc Posted August 19, 2010 Author Share Posted August 19, 2010 Just realized that there might be variables after &limit= that I would want to keep... So I'm back to: //remove any old limit from query $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '?' . implode('&',$tmp); Just trying to flush the current "limit"... this has worked in other instances for me before. ~Wayne Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.