SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Possible to make a variable "POST" even if not actually submitted by browser?

    Hello,

    Is it possible to create a variable that uses the special "POST" value even if it was not actually submitted by the browser?

    For example...

    I have a form_processing.php script that is already created and working. It adds some values to a database based on a webpage form that is submitted. The script uses $_POST for all the "incoming" values, like this:

    PHP Code:
    if ($_POST['message'] == "whatever") { //insert into database } 
    What I would like to do is "call" this form_processing script from another script that runs by email piping, so that the form_processing.php script can run from an email instead of a webpage form.

    So for example, in my email piping script (executed when an email is received), I have something like this:

    PHP Code:
     //parse the email and extract $subject and $message

    $_POST['message'] = $message;
    $_POST['subject'] = $subject;

    //Now "call" the form_processing.php script.
    include('form_processing.php'); 
    Will that work? Will the "form_processing.php" script behave as if it is receiving the $_POST values from a browser?

    (I have tested, but can't seem to get this working, so I wanted to ask before I spend more time trying to figure it out...)

    Thanks!
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Yes, you can create the $_POST array manually if you want.

    You handler might look something like this:

    PHP Code:
    <?php

    // look for evidence that a mandatory field has been filled in and submitted
    // as a post var

    if( !isset($_POST['subject'])){

    // $message has got to come from somewhere else
    // the re-assign it so that it becomes part of the 
    // $_POST array

    $_POST['message'] = $message;
    $_POST['subject'] = $subject;

    }


    // continue as normal, accessing a single array 
    // of $_POST vars

    echo $_POST['subject'] . ' - ' $_POST['message'];

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    You can. You shouldn't but you can. The input arrays should, in theory, be read only attributes. In practice they do get written to, especially when fighting balls of mud code. I'm presuming this form_processing block of code is already written and debugged and you just don't want to tamper with it, so that's fine - if you are in a hurry. If you have the time you need to separate the form processing logic (reading $_POST ) from the actual database writing mechanism. Then you can create your own data and bypass the form filtering step.

  4. #4
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    I'm presuming this form_processing block of code is already written and debugged and you just don't want to tamper with it,
    Exactly. The form_processing.php script is a "black box" that I am not able to modify or even see because it's encrypted... I know it accepts $_POST variables since I can view the HTML form.

    So I'm basically wanting to "run" the form_processing.php script directly via email piping instead of manually from a webpage submission.

    Thanks!
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •