0

How can I update a url variable value? The url will look like that for example:

www.example.com/product.php?.........&page=1...........

I would like to change page value from 1 to 2, the reason that I typed dots instead of real url is since the url is dynamic and not static.

So how can I do that?how can I update and url variable value?

EDIT

I will refresh the page with the new value so the page will be re-filtered.

Imri Persiado
  • 1,857
  • 8
  • 29
  • 45

2 Answers2

0

Can you try this,

     $QUERY_STRING = $_SERVER['QUERY_STRING'];
    echo  $QUERY_STRING =  str_replace('page=1', 'page=2',  $QUERY_STRING);
Krish R
  • 22,583
  • 7
  • 50
  • 59
0

PHP does not control your browser. The user and/or Javascript does. This means, you can not update a specific variable in the URL. (This variable is also called a HTTP GET Parameter).

What you have are below options:

  • Use an HTML form, with action="" & method=GET. Use hidden fields, with name=page and value=<number>.

    <form action="" method="GET">
        <input type="hidden" name="page" value="2" />
    
        <!-- Use PHP to echo out all other GET parameters into hidden form fields -->
    
        <input type="submit" value="click me to go to page 2"/>
    </form>
    
  • Use Javascript: Parse out the GET parameters, and modify it.
Community
  • 1
  • 1
UltraInstinct
  • 43,308
  • 12
  • 81
  • 104
  • But I want to change the value from a link, and not after a submit button clicked.. because the page 1,2,3,4 are links. – Imri Persiado Nov 16 '13 at 19:54