0

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.

6 Answers 6

4

Fairly simply, you can do this

$_GET['p2'] = 100;
header("Location: http://www.domain.com" . $_SERVER['REDIRECT_URI'] . '?' . http_build_query($_GET));
Sign up to request clarification or add additional context in comments.

Comments

0

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"

Comments

0

Reload your page you just have to setup your variables the way you want it in the URL field

Comments

0

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. :)

Comments

0

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' );

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.