user198729
user198729

Reputation: 63626

Is there a reliable way to know whether a request is in an Ajax context in PHP?

I need to deal with these two cases differently,is there a good solution?

Upvotes: 3

Views: 127

Answers (2)

Asaph
Asaph

Reputation: 162781

I can think of 2 ways to accomplish this:

Upvotes: 3

Sergei
Sergei

Reputation: 2757

if ($_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') { /* ajax request */ }

Upvotes: 6

Related Questions