obaluba Posted May 6, 2013 Share Posted May 6, 2013 Hi all, I'm hoping someone can help me with something I think or hope is pretty simple. I have an editable pdf form which people fill out on a website. when the user clicks submit the script emails the completed pdf to an email address and stores a copy on the server. however, if i go directly to the script on the server i.e.: www.domain.com/script.php and press enter it will email me a pdf file with nothing in it to my address what I want to do is try and stop this as its causing issues with the form.. I was hoping there was something that could go in the header that could help.. when the user clicks submit the path from the submit button is directly to the code below the code is here <?php require("class.phpmailer.php"); /////////////////////////////////////////////////// ////////////////////////////////////////////////// /////////////////////////////////////////////////// ////////////////////////////////////////////////// /* $folder = "";*/ $folder = "/home/account/public_html/path/pdf/"; $fn = $folder . date("d-m-Y-His").'.pdf'; # make unique filename copy('php://input',$fn); # copy raw post data to file /////////////////////////////////////////////////// ////////////////////////////////////////////////// // use for Upload folder >>>>>>>>>>>>>>>>> $mail = new PHPMailer(); $mail->MsgHTML($body); $mail->AddAddress("email@gmail.com"); $mail->From = "address@email.com"; $mail->FromName = 'PDF Form enquiry'; $mail->Subject = 'Completed Form'; $mail->Body = 'Attached is a user submitted form'; $thankyouurl = "www.domain.com/thanks" ; if(!$mail->AddAttachment($fn)) { echo "There was a problem attaching the pdf form."; echo $mailer->ErrorInfo; } $dataResponse_1 = "passed"; if(!$mail->Send()) { print("&response=error"); } else { header( "Location: $thankyouurl" ); } ?> thanks so much for looking! Quote Link to comment https://forums.phpfreaks.com/topic/277693-block-a-php-scrip-from-being-run-directly/ Share on other sites More sharing options...
Mad programmer Posted May 6, 2013 Share Posted May 6, 2013 (edited) Hello, If you include the script from another script you can set a variable like: $allowSend = true; And then simply check if that variable is not null and is true, else exit. If it is a standalone script you may use sessions for this. Edited May 6, 2013 by Mad programmer Quote Link to comment https://forums.phpfreaks.com/topic/277693-block-a-php-scrip-from-being-run-directly/#findComment-1428548 Share on other sites More sharing options...
obaluba Posted May 6, 2013 Author Share Posted May 6, 2013 Thanks for your reply. Is there nothing simple I can add into the script i have to enable it to stop running and only run through the pdf form? thanks again Quote Link to comment https://forums.phpfreaks.com/topic/277693-block-a-php-scrip-from-being-run-directly/#findComment-1428559 Share on other sites More sharing options...
Jessica Posted May 6, 2013 Share Posted May 6, 2013 Move it out of the web root. Quote Link to comment https://forums.phpfreaks.com/topic/277693-block-a-php-scrip-from-being-run-directly/#findComment-1428589 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.