Tarik
Tarik

Reputation: 81721

Page.IsPostBack equivalent in PHP

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 special 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.

Upvotes: 3

Views: 12430

Answers (4)

Neil Knight
Neil Knight

Reputation: 48547

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

Upvotes: 5

SAIF
SAIF

Reputation: 189

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

Upvotes: 0

Edoardo Pirovano
Edoardo Pirovano

Reputation: 8334

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.

Upvotes: 2

Daniel Gruszczyk
Daniel Gruszczyk

Reputation: 5622

I am always using

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

Upvotes: 5

Related Questions