Jump to content

block a php scrip from being run directly


obaluba

Recommended Posts

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!

Link to comment
Share on other sites

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 by Mad programmer
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.