Can I POST and GET to the same PHP page

2019-06-20 18:13发布

I wanted to know if it is possible to GET and POST on the same php page, for example

I want to send data to:

http://www.example.com/my.php

So first the GET

http://www.example.com/my.php?task=dosomething

and POST some $thexml = XML to

http://www.example.com/my.php?task=dosomething

and then be able to access both in some code like (example)

// Example Code ============================

    if($_GET["task"] == "dosomething"){
      $mynewxml = $_POST["$thexml"];
    }
//==========================================

标签: php xml post get
7条回答
闹够了就滚
2楼-- · 2019-06-20 19:12

Sure. Quite easy:

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  ... handle form submission here ...
}

?>

<html>

<body>

<form action="thisscript.php" method="post">
... form here ...
</form>
查看更多
登录 后发表回答