POST from inside PHP script

This is a discussion on POST from inside PHP script within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I want to launch a page with parameters depending on certain input, I was thinking of doing this : header(&...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-18-2006
Peter
 
Posts: n/a
Default POST from inside PHP script

Hi,

I want to launch a page with parameters depending on certain input,
I was thinking of doing this :

header("Location: $newurl");

where $newurl is something like this :
http://www.site.com/?val1=1&val2=2&val3=3

Now, this way one can see easily what the variables are and one can try to
vary on the theme to see what other output can be generated.

So I'm wondering how to send these variables along but not in the URL (via
GET I suppose) but via POST instead ?


Reply With Quote
  #2 (permalink)  
Old 01-18-2006
Adam Plocher
 
Posts: n/a
Default Re: POST from inside PHP script

Peter, I've done this before in the past but I can't remember exactly
how, so I can't provide you with a code example. Instead, I can point
you in the right direction. Take a look at PHP's CURL (Client URL)
stuff. You can find information about it here: http://us2.php.net/curl

This should do what you need.

Reply With Quote
  #3 (permalink)  
Old 01-20-2006
rlee0001
 
Posts: n/a
Default Re: POST from inside PHP script

Peter,

Can you rely on the client having session cookies enabled?

I'm doing something like this for a client and I have had success
creating a temporary (undated/session) cookie for each of my variables
when I issue the header("Location... call. Then on the page accepting
the input at the very top I send headers to delete those cookies
(setcookie with a false value) at the very top. The page will still be
able to access the cookie array even after you sent the erase command
to the client.

I my case I am doing this:

myform.html
if cookie exists:
delete it via response headers
print it to the user
output this form:
hidden field: returnto = server(requesturi)
(other fields)
action: process.php
method: POST
exit

process.php
(process other data fields)
set cookie with the success code of the processing
redirect to post(returnto)
exit

The affect is that it looks like the user never navigated at all even
after two round trips. Even the back button/browser history records no
navigation history. So the user never gets hit with one of those "This
page has expired, resubmit form data?" prompts.

In my opinion this is the best way to submit a form (POST in then
redirect back). Specifying return values in cookies is really the same
as using sessions and in a more complex application you can do that as
well. I decided that sending a session variable then storing the data
on the server was overkill for sending a return value from a form.

Reply With Quote
  #4 (permalink)  
Old 01-20-2006
Peter
 
Posts: n/a
Default Re: POST from inside PHP script

Thanks both for the feedback.
Somehow I thought it would be as easy as one line of code (possibly simply
another header with POST data instead of the data in the URL).
Because I'm really not that good using php (first steps) and certainly not
cookies (know nothing about it) and this is only for a "fun after work" type
thing for a local youth group (project due soon) I'm not going to bother
implementing more complex things (although I do get inspiration from these
posts ;-)) but I have to refrain myself and stick to the more needed things
that still need implementing.


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:58 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0