How can you determine if the input a script is receiving is coming in via a form POST vs. STDIN (such as an email message being piped in)
i.e. the same script needs to do something different depending on how it's being run. Suggestions?
Programming question
Moderators: BBear, theunknownhost, flaguy
- theunknownhost
- Official Test Penquin
- Posts: 2713
- Joined: Mon Aug 05, 2002 1:05 pm
I would place a hidden variable in the form.
i.e.
Then tell the program to check for the value of $myvar - Logic
i.e.
Code: Select all
<input type=hidden name=myvar value=5>
Then tell the program to check for the value of $myvar - Logic
Code: Select all
if ($myvar=='5'){
this was submitted using the form
}
else{
it must have been piped in
}
m2 is right REQUEST_METHOD will tell you whether its POST, GET, HEAD, or PUT.
I can't tell from your question but if its for form security theunknownhost is on the right track but I would do it a bit differently, as the remote POST call could check your page source and just post that variable also.
I would create a one time random token and put it in a session variable and then put it in a hidden form field. The on submit check the form field against the session field for a match to determine if the post was good.
I can't tell from your question but if its for form security theunknownhost is on the right track but I would do it a bit differently, as the remote POST call could check your page source and just post that variable also.
I would create a one time random token and put it in a session variable and then put it in a hidden form field. The on submit check the form field against the session field for a match to determine if the post was good.
Thanks for your help.
Yes, the presence of any REQUEST_METHOD value will indicate the data came from a form submission. Its absence will tell me the data came in otherwise. In fact, I discovered that all of the usual CGI ENV vars which we are accustomed to seeing are NOT SET when the data is incoming via email messages piped to the script. in this case the ENV vars which are set are those set by procmail during processing and delivery of the email message.
I will use SERVER_PORT whose value will be 80 or 443 (via https) or it will be completely unset/absent if the data is coming in via email message piped to the script.
Similarly, a third set of ENV vars are present when running a script directly via command line. In that case, what you get are ENV vars set by the shell program.
I just need different parsing subroutines depending on whether the info is submitted via form or via email. There doesn't seem to be one ENV var that is present in both cases. This needs to be determined before any data from the submission can be read, so an extra form field will not work.
Thanks again.
Yes, the presence of any REQUEST_METHOD value will indicate the data came from a form submission. Its absence will tell me the data came in otherwise. In fact, I discovered that all of the usual CGI ENV vars which we are accustomed to seeing are NOT SET when the data is incoming via email messages piped to the script. in this case the ENV vars which are set are those set by procmail during processing and delivery of the email message.
I will use SERVER_PORT whose value will be 80 or 443 (via https) or it will be completely unset/absent if the data is coming in via email message piped to the script.
Similarly, a third set of ENV vars are present when running a script directly via command line. In that case, what you get are ENV vars set by the shell program.
I just need different parsing subroutines depending on whether the info is submitted via form or via email. There doesn't seem to be one ENV var that is present in both cases. This needs to be determined before any data from the submission can be read, so an extra form field will not work.
Thanks again.
Who is online
Users browsing this forum: No registered users and 1 guest