Jump to content

Clear Page With Submit


TKO

Recommended Posts

I have this code that will call the page and clear it but what im trying to figure out is how to execute the code only when submit button is pressed.

 

<?php
$address = "example.php";
$fp = fopen("$address",'w+');
if(!$fp)
   echo 'not Open';
    //-----------------------------------
while(!feof($fp))
 {
    fputs($fp,' ',999);				   
 }
fclose($fp);
?>

 

Thank you

Link to comment
Share on other sites

if (isset($_POST['submit_button'])) {
// Your code here
}

 

This is the way I have always done it, but someone on this forum recently wrote that not all browsers submit a value of submit buttons. I haven't tried to verify this. With the code above, you are relying on this. The value of your submit button (i.e. the text) will be submitted, and therefore the if statement will evaluate to true. You could also do like below:

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Post request
}

 

This just checks if the request is a post request and technically not if your button was pressed (a post request could be made even if it wasn't, but that's a technicality).

 

Edit: Found it! Please see this post by AyKay47.

Edited by Andy123
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.