开发者

Page.IsPostBack equivalent in PHP

开发者 https://www.devze.com 2023-03-17 15:52 出处:网络
When working on the same page which accepts Post data, it is good to know whether there is a special function like the one in Asp.NET such as Page.IsPostBack. Maybe I could use isset($_POST) but I am

When working on the same page which accepts Post data, it is good to know whether there is a special function like the one in Asp.NET such as Page.IsPostBack. Maybe I could use isset($_POST) but I am thinking there could be a spe开发者_运维问答cial function for that.

So I want to process the post data under that function give alerts during processing the post data, otherwise it is just a page request.


I am always using

if($_SERVER['REQUEST_METHOD'] == 'POST')


Maybe you could use:

if (count($_POST))

as this will return either 0 or 1.

Or:

// Determine whether the page was requested via GET or POST.
function isPostBack() { 
    return ($_SERVER['REQUEST_METHOD'] == 'POST');
}


I don't think there's a function specifically for that. I would just do count($_POST) to check if the $_POST array contains anything.


function isPostBack()
{
   return (count($_POST) > 1);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消