ShaolinF Posted October 15, 2007 Share Posted October 15, 2007 Hi Guys, I have 2 pages, a form (form.php), and a script (process.php). Now what I want to do is, if someone tries to directly access process.php then he will get redirected back to form.php, but if a user submitts a form via form.php then it will get processed by process.php - How can I do this ? Quote Link to comment https://forums.phpfreaks.com/topic/73384-_post/ Share on other sites More sharing options...
drewjoh Posted October 15, 2007 Share Posted October 15, 2007 You could check the $_SERVER['HTTP_REFERER'], but this isn't 100% reliable. You could set a session variable on form.php, and check for it on process.php. If it's not there, then they didn't go to form.php first. That solution only works once though. Or, you could set a hidden variable to pass through, and check for that. <input type="hidden" name="valid_user" value="true" /> Or, you could check that all the fields have been set (or at the least the ones that have to), and if they're not... send them back to form.php. <?php if(!isset($_POST['name'])) header("Location: URL/form.php"); // They didn't enter their name or they came to process.php directly! Quote Link to comment https://forums.phpfreaks.com/topic/73384-_post/#findComment-370259 Share on other sites More sharing options...
simcoweb Posted October 15, 2007 Share Posted October 15, 2007 You could, as well, use something that makes sure the form was actually submitted: if (isset($_POST['submit'])){ // all your code here } else { header("Location: form.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/73384-_post/#findComment-370263 Share on other sites More sharing options...
ShaolinF Posted October 16, 2007 Author Share Posted October 16, 2007 excellent stuff guys. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73384-_post/#findComment-370264 Share on other sites More sharing options...
prime Posted October 16, 2007 Share Posted October 16, 2007 simcoweb's code is deinfately the best way to go Quote Link to comment https://forums.phpfreaks.com/topic/73384-_post/#findComment-370414 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.