Reputation: 481
let say I have an url like this
http://www.domain.com/myscript.php?p1=xyz&p2=10&p3=ghj
Now i want to update p2=100
and reload the page using php
here parameters can be unlimited (p1,p2,...pn)
, and we can update any param and reload the page.
Upvotes: 0
Views: 5639
Reputation: 1219
Try below codes:
$varURL = 'http://www.domain.com/myscript.php?p1=xyz&p2=10&p3=ghj';
$varNEwURL = preg_replace('/p2=([0-9]*)&/', 'p2=100&', $varURL);
header('location:'.$varNEwURL);
OR
$varURL = 'http://www.domain.com/myscript.php?p1=xyz&p2=10&p3=ghj';
$varNEwURL = $varURL.'&p2=100';
header('location:'.$varNEwURL);
Upvotes: 0
Reputation: 12433
Here is what I use when I want to change 1 $var
value and then redirect.
function getUrlWithout($getNames){
$url = $_SERVER['REQUEST_URI'];
$questionMarkExp = explode("?", $url);
$urlArray = explode("&", $questionMarkExp[1]);
$retUrl=$questionMarkExp[0];
$retGet="";
$found=array();
foreach($getNames as $id => $name){
foreach ($urlArray as $key=>$value){
if(isset($_GET[$name]) && $value==$name."=".$_GET[$name])
unset($urlArray[$key]);
}
}
$urlArray = array_values($urlArray);
foreach ($urlArray as $key => $value){
if($key<sizeof($urlArray) && $retGet!=="")
$retGet.="&";
$retGet.=$value;
}
return $retUrl."?".$retGet;
}
This takes the url ($_SERVER['REQUEST_URI']
), removes the desired values ($getNames
) [which can be one or more values], and rebuilds the url. It can be used like-
$newurl = getUrlWithout(array("p2"));
header( 'Location: http://www.domain.com/'.$newurl.'&p2=100' );
Upvotes: 0
Reputation: 83
If you want to reload page with desired parameters use JS
Following script might help you
window.location = "http://www.domain.com/myscript.php?p1=xyz&p2=100&p3=ghj"
window.location = "http://www.domain.com/myscript.php?p2=200&p1=dfgb&p3=asdhahskh&etc=alotofparameters"
Now if you want to reload the page after a specific amount of time interval then you can use the following meta tag
<meta http-equiv="refresh" content="30; ,URL=http://www.metatags.info/login">
Njoy Coding. :)
Upvotes: 0
Reputation: 2442
Reload your page you just have to setup your variables the way you want it in the URL field
Upvotes: 0
Reputation: 2784
The question is kind of vague, but assuming you want to reload from the client side using javascript:
window.location = "http://www.domain.com/myscript.php?p1=xyz&p2=100&p3=ghj"
Upvotes: 0
Reputation: 6752
Fairly simply, you can do this
$_GET['p2'] = 100;
header("Location: http://www.domain.com" . $_SERVER['REDIRECT_URI'] . '?' . http_build_query($_GET));
Upvotes: 4