Lectrician Posted March 21, 2009 Share Posted March 21, 2009 I have a form submitted to a PHP script. Is there a way to use PHP to tell if the page which the form was submitted to is fresh from the form or has been refreshed by the user? Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/ Share on other sites More sharing options...
redarrow Posted March 21, 2009 Share Posted March 21, 2009 php is server side, and has no control over client activity. JavaScript might help it client based. you can cheek if the form was submitted but not refreshed with php. if(isset($_POST['submit'])){ <<< submit is the name of the form, submit button. } Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-790188 Share on other sites More sharing options...
DeanWhitehouse Posted March 21, 2009 Share Posted March 21, 2009 One bad way (kinda hack) to do it would be to store a session when the user first visits the page and submits the form, then in the form validation code check if the session is there. Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-790211 Share on other sites More sharing options...
Lectrician Posted March 27, 2009 Author Share Posted March 27, 2009 Thanks. I have been googling, and it seems you can send some form POST data via headers? I have tried this code, but it returns a server error, with the log showing that the headers where malformed? Any ideas? <?php $host = "www.example.com"; $path = "/path/to/script.php"; $data = "data1=value1&data2=value2"; $data = urlencode($data); header("POST $path HTTP/1.1\r\n" ); header("Host: $host\r\n" ); header("Content-type: application/x-www-form-urlencoded\r\n" ); header("Content-length: " . strlen($data) . "\r\n" ); header("Connection: close\r\n\r\n" ); header($data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-795388 Share on other sites More sharing options...
doublezer0 Posted March 27, 2009 Share Posted March 27, 2009 i would store the contents of the form in a session and then check it to see if they are the same values or if it is empty when the form is submitted Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-795469 Share on other sites More sharing options...
Lectrician Posted March 28, 2009 Author Share Posted March 28, 2009 If the page is refreshed though, the form data would be set ack into the session and so would exist? Or am I barking? Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-795674 Share on other sites More sharing options...
chokitofrito Posted March 28, 2009 Share Posted March 28, 2009 quick answer: if (isset($_SESSION['viewed'])) { $_SESSION['viewed'] = $_SESSION['viewed'] + 1 } else $_SESSION['viewed'] = 0 } if more than 1, it means it was refreshed or something like that.. Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-795675 Share on other sites More sharing options...
Lectrician Posted March 28, 2009 Author Share Posted March 28, 2009 Thanks. When the form is submitted a new page opens through my perl script. When you hit the back button to go back to this blank php page and then press refresh (because the page has expired), the session will have been cleared wont it? So when ever the php is executed the session will be renewed? Quote Link to comment https://forums.phpfreaks.com/topic/150447-php-form/#findComment-795746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.