Prevent PHP Post script from being run

Discussion in 'PHP' started by blackburn2413, Aug 10, 2011.

  1. #1
    Hey everyone, what I am guessing is a small problem has me stuck. Just looking for a quick pointer. Basically I have a form on my site. When you submit it, it directs you to another page that actually takes the data (via POST and stores as php variables) and then it ends up doing a couple things including sql queries and a php mail script.

    My problem is that I think when browsers and maybe other users are going directly to this page, it is making blank queries and sending blank emails because obviously the variables that would normally be there from the form and POST are empty, because the user browsed directly to this action page.

    Is there any way to stop this page from loading unless a person is referred to it from my original page that houses the form?

    Any ideas?
     
    Solved! View solution.
    blackburn2413, Aug 10, 2011 IP
  2. #2
    send another variable along with the post script a hidden variable and then on the receiving page check that the hidden variable = what you set it to if not do not do what is on the page.
     
    ausrixy, Aug 10, 2011 IP
  3. MarPlo

    MarPlo Member

    Messages:
    97
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    48
    #3
    Hy,
    As addition, to pass the value of the variable from a page to another, store it in $_SESSION.
    Also check if data was send from the form, with if(isset($_POST['field_name']))
     
    MarPlo, Aug 11, 2011 IP
  4. blackburn2413

    blackburn2413 Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Thank you both. I went through and did the first suggestion early this morning. In each form, I set a hidden value named 'verify' and set it to a value of 1. Then on the page that the form passed to I included the following code:

    
    $verify = $_POST["verify"];
    if ($verify == 1)
    	{
             INSERT-THE-REST-OF-MY-SQL-QUERIES-AND-OTHER-CODE-HERE
            }
    
    
    
    Code (markup):
    This way if someone is referred to this page or tries to run it directly, the $verify variable will not have a value of 1 and thus, wont work. Problem solved!
     
    blackburn2413, Aug 11, 2011 IP