Re: Post with redirect?



Steve wrote:
"taps128" <nstjelja@xxxxxxxxx> wrote in message news:fk5ecm$h6e$1@xxxxxxxxxxxxxxxxx
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:
"UKuser" <spiderc...@xxxxxxxxxxx> wrote in message
news:5202d2ed-02a2-407d-87ca-a6a2b50a283c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 14 Dec, 14:42, "Steve" <no....@xxxxxxxxxxx> wrote:
"UKuser" <spiderc...@xxxxxxxxxxx> wrote in message
news:6d60314f-61f0-4f08-b1ad-b6cf357cac15@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 14 Dec, 12:48, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
UKuser wrote:
Hi,
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
Not easy, and it can't be done with PHP. The browser needs to
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
==================
Thanks for your help. Should have realised because its server side
it
makes it impossible. Any thoughts on how it could be done with
AJAX/JS?
don't let the misinformation fool you. it can be done with php. the
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.
Hi Guys,
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.
as a general and theoretical approach:
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?
Hi Steve,
Thanks for your detailed response. Would that be able to redirect the
user to the same page as where the data was posted?
if you collect information via a page called my.php, put the above code in
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.
some time ago I found a nice piece of code that helps me to access a script using post using the standards php streams wrapper

$postdata = http_build_query(

array(

'var1' => 'some content',

'var2' => 'doh'

)

);

$opts = array('http' =>

array(

'method' => 'POST',

'header' => 'Content-type: application/x-www-form-urlencoded',

'content' => $postdata

)

);

$context = stream_context_create($opts);

$result = file_get_contents('http://localhost/vjezba/post_u_skriptu_2.php', false, $context);


print_r(explode(' ',$result));

yes, but jerry seems to think that using this method of putting items in a user's cart on another server is impossible...and that using an html form with the same inputs as is native on the server's checkout form to initiate payment is likewise, impossible. he gets hung up on having to use javascript to do a redirect. php and standard html handle all of that just fine. just don't tell him that.




Again, you claim you can do a redirect with posted values in PHP. Let's see you do it, Steve. The entire world is STILL waiting for you to show us how!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • Re: Post with redirect?
    ... He wanted a way to redirect a port with data to an external site ... posting certain inputs, with the 3rd party server as the target. ... i made no claim other than you can use just php to get the job done. ... only thing jerry got right is that it would be a lot of work. ...
    (comp.lang.php)
  • Re: Post with redirect?
    ... you made it about javascript, ... He wanted a way to redirect a port with data to an external site and I gave it to him. ... And you still haven't showed us how to do a redirect with post values in PHP. ... the only thing jerry got right is that it would be a lot of work. ...
    (comp.lang.php)
  • Re: Post with redirect?
    ... I am using an online merchant provider and I must post certain ... How can I force a POST but actually redirect the user as well ... and it can't be done with PHP. ... thing jerry got right is that it would be a lot of work. ...
    (comp.lang.php)
  • Re: Post with redirect?
    ... yes, but jerry seems to think that using this method of putting items in a user's cart on another server is impossible...and that using an html form with the same inputs as is native on the server's checkout form to initiate payment is likewise, impossible. ... you claim you can do a redirect with posted values in PHP. ... Steve. ...
    (comp.lang.php)
  • Re: Post with redirect?
    ... and it can't be done with PHP. ... the redirect, so you need to do it from the browser end. ... thing jerry got right is that it would be a lot of work. ... mistakenly forgets is that just about anything you can do with curl, ...
    (comp.lang.php)