php_self posting problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gavski1
Forum Newbie
Posts: 7
Joined: Thu Jan 16, 2014 4:59 pm

php_self posting problem

Post by Gavski1 »

I have a form that contains a function. i want this function to be activated only when the user reposts the page to itself. (php_self).

ie. the user access the page and the function is hidden, the user then inputs data, repost the page and the function is activated.

I've tried flagging the function with a variable - $var = 0, then $var = 1 at the end of the page but $var just resets itself to 0 when the page is posted.

Sure this is simple but I just cant get it?


thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php_self posting problem

Post by Celauran »

Code: Select all

if (!empty($_POST)) {
    // do stuff after form has been submitted
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php_self posting problem

Post by requinix »

Also mentioned recently, somewhere, is looking at the REQUEST_METHOD.

Code: Select all

if ($_SERVER["REQUEST_METHOD"] == "POST") {
Gavski1
Forum Newbie
Posts: 7
Joined: Thu Jan 16, 2014 4:59 pm

Re: php_self posting problem

Post by Gavski1 »

YES!, thanks guys,
both of these work fine, I love a simple solution! :D
Post Reply