How to set $_GET variable

2019-01-15 13:02发布

How do i set the variable that the $_GET function will be able to use, w/o submitting a form with action = GET?

9条回答
萌系小妹纸
2楼-- · 2019-01-15 13:25

You can create a link , having get variable in href.

<a href="www.site.com/hello?getVar=value" >...</a>
查看更多
唯我独甜
3楼-- · 2019-01-15 13:25

You can use GET variables in the action parameter of your form element. Example:

<form method="post" action="script.php?foo=bar">
    <input name="quu" ... />
    ...
</form>

This will give you foo as a GET variable and quu as a POST variable.

查看更多
迷人小祖宗
4楼-- · 2019-01-15 13:27

I know this is an old thread, but I wanted to post my 2 cents...

Using Javascript you can achieve this without using $_POST, and thus avoid reloading the page..

<script>
function ButtonPressed()
{
window.location='index.php?view=next'; //this will set $_GET['view']='next'
}
</script>

<button type='button' onClick='ButtonPressed()'>Click me!</button>

<?PHP
 if(isset($_GET['next']))
    {
          echo "This will display after pressing the 'Click Me' button!";
    }
 ?>
查看更多
登录 后发表回答