For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2006 > POST from inside PHP script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author POST from inside PHP script
Peter

2006-01-18, 6:57 pm

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 ?


Adam Plocher

2006-01-18, 6:57 pm

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.

rlee0001

2006-01-19, 9:55 pm

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.

Peter

2006-01-20, 7:56 am

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.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com