Re: Post with redirect?
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Fri, 14 Dec 2007 17:41:30 -0500
UKuser wrote:
On 14 Dec, 16:22, "Steve" <no....@xxxxxxxxxxx> wrote:"UKuser" <spiderc...@xxxxxxxxxxx> wrote in message
news:6c8d667d-a40b-45c2-bc03-94951dbc137f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 14 Dec, 15:18, "Steve" <no....@xxxxxxxxxxx> wrote:if you collect information via a page called my.php, put the above code in"UKuser" <spiderc...@xxxxxxxxxxx> wrote in messageHi Steve,
news:5202d2ed-02a2-407d-87ca-a6a2b50a283c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 14 Dec, 14:42, "Steve" <no....@xxxxxxxxxxx> wrote:as a general and theoretical approach:"UKuser" <spiderc...@xxxxxxxxxxx> wrote in messageHi Guys,
news:6d60314f-61f0-4f08-b1ad-b6cf357cac15@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 14 Dec, 12:48, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:don't let the misinformation fool you. it can be done with php. theUKuser wrote:Thanks for your help. Should have realised because its server sideHi,Not easy, and it can't be done with PHP. The browser needs to
I'm not sure if this can be done as I've searched the web and
this
forum.
I am using an online merchant provider and I must post certain
variables to their webforms through a form on my website.
The issue is that I need to gauge whether a user has any items in
their basket to decide which page I redirect them too. I could
obviously use cookies or hidden fields etc but these can be
manipulated.
How can I force a POST but actually redirect the user as well
like a
browser would do? I can do the first part (force the post) as per
this
site (the site appears down, so the link uses the Web Archive):
http://web.archive.org/web/20040628200619/http://www.zend.com/zend/sp...
Its the second bit if I'm not sure whether it can or can't be
done.
If not I'll need to ask the merchant if they allow GET instead.
Many thanks
A
process
the redirect, so you need to do it from the browser end. That
means a
client-side language such as javascript.
cURL could theoretically help you here - but you're asking for a
lot
of
work, especially if there are several pages being handled after the
redirect. You'd have to parse each page to see what to do next.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@xxxxxxxxxxxxx
==================
it
makes it impossible. Any thoughts on how it could be done with
AJAX/JS?
only
thing jerry got right is that it would be a lot of work. what jerry
also
mistakenly forgets is that just about anything you can do with curl,
you
can
do with native php functions...and in this case, the 'just about
anything'
you'd need to be able to do becomes 'anything'. jerry's 'curl could
theoretically' argument then logically negates and invalidates his
'cant
be
done with php' claim.
you're just in for a lot of work. however, it can be done.
I'm not greatly up for a huge deal of work although would be
interested in how you would generally start doing it in PHP. However I
found another posting on a forum which works and is much easier. Not
ideal although we are really only (and i know its aweful) aiming our
website at Javascript users.
function getResponse($uri, $path, $data, $method = 'POST')
{
$method = strtoupper($method);
$socket = fsockopen($uri, 80);
if (!$method)){ $method = 'GET'; }
if (substr($path, 0) != '/'){ $path = '/' . $path; }
if (!is_array($data)){ $data = array($data); }
$message = '';
foreach ($data as $label => $value)
{
$message .= '&' . $label . '=' . $value;
}
if ($method == 'GET'){ $path .= '?' . $message; }
fputs($socket, "$method $path http/1.1\r\n");
fputs($socket, "host: $uri\r\n");
fputs($socket, "content-type: application/x-www-form- urlencoded\r\n");
fputs($socket, "content-length: " . strlen($message) . "\r\n");
fputs($socket, "connection: close\r\n\r\n");
if ($method == 'POST'){ fputs($socket, $message); }
while (!feof($socket)){ $response .= fgets($socket, 512); }
fclose($socket);
return $response;
}
$response = getResponse(
'www.example.com',
'some.page.php' ,
$_POST ,
'POST'
);
// parse, validate, process
effectively, this achieves your html/javascript solution and keeps it all
php.
that help?
Thanks for your detailed response. Would that be able to redirect the
user to the same page as where the data was posted?
it. have my.php post to itself. when you get the post, pass the info on to
the third party via getResponse...then parse the results...you haven't done
any redirecting and the user has used my.php the entire time.
make sense?
Yes it does, unfortunately I have to redirect the user to the page as
its a credit card entry form on a completely separate server. They
don't appear to accept GET requests only POSTS so I somehow need to
get the information and the user to that page.
And therein lies the problem I was referring to.
If you use cURL or the socket equivalent to cURL to post the page to the server, you get a response back. But now you have to parse that page for all of the possible responses - was it good or bad? If bad, what was wrong with it? Is it something on your end or did the user enter some invalid data? Is the card over the limit?
And what do you do if they change the page layout? Or the text? You have to go back to your parsing routine.
And you can't just return the page to the user. What happens if there is a relative link on the page? Not to mention if there are any images, links to CSS/javascript files, etc., from the company, you would need to handle the subsequent requests from the browser for those (and of course, their URI might change).
Note I never said it couldn't be done. Posting the page to the server is the easy part. The response is where it gets hard. And that's what I'm fighting right now for one customer - I need the go/bad response from the server to be able to continue processing if it was OK.
But Stevie never bothered to think that far ahead.
Since your target audience will have JavaScript enabled anyway, that's a much better way to go. I've used it on a couple of sites.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Post with redirect?
- From: Steve
- Re: Post with redirect?
- References:
- Post with redirect?
- From: UKuser
- Re: Post with redirect?
- From: Jerry Stuckle
- Re: Post with redirect?
- From: UKuser
- Re: Post with redirect?
- From: Steve
- Re: Post with redirect?
- From: UKuser
- Re: Post with redirect?
- From: Steve
- Re: Post with redirect?
- From: UKuser
- Re: Post with redirect?
- From: Steve
- Re: Post with redirect?
- From: UKuser
- Post with redirect?
- Prev by Date: Re: Post with redirect?
- Next by Date: Re: XML encoding
- Previous by thread: Re: Post with redirect?
- Next by thread: Re: Post with redirect?
- Index(es):
Relevant Pages
|
Loading