Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2004, 10:08 PM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting $_POST

Is there some way to set $_POST array contents before doing a redirect from a PHP program?

Perhaps I'm asking the wrong question; The goal is to invoke a remote web site that expects a type=POST http request, with several hidden form fields filled in. I'd like to invoke this site from a PHP program. I don't see how to set the "simulated" form fields prior to jumping to that remote site.

Further, whatever mechanism I use must work under SSL.

I think this has got to be easy, but I've searched all over looking for references or suggestions, but have come up empty. Can someone point me in the right direction? Thanks.
-don
 
Old January 17th, 2004, 11:04 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I dunno Don, that seems like a tall order to me.

You would basically have to recreate the entire process of an HTTP request sending POST data.. more or less creating a browser application in PHP.

I did a bit of searching on Google and came up with this:
http://snoopy.sourceforge.net/

Seems to fit the bill, and the site says it supports SSL! You can't beat free and already put together!

hth,
: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 18th, 2004, 08:45 AM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rich, thanks! I had searched Google with all sorts of queries, but never came across Snoopy; Initial poke indicates this will solve my problem. I'm very grateful for your response.
-don
 
Old January 18th, 2004, 11:05 AM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh Dear --
Closer examination of Snoopy reveals that for SSL requests, it uses (requires) CURL under the hood. Unfortunately, for "security reasons" (which I don't understand), our web host service will not provide or allow CURL.

So close...

Anyone have any other suggestions?
Thanks.
-don
 
Old January 19th, 2004, 02:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That sucks. I was going to suggest using cURL anyway -- ignore all this snoopy crap.

PHP supports cURL natively via the cURL extension:
  http://www.php.net/curl


That said, if your web hosting company won't install curl for all users, you might get away with compiling the binary for yourself and using PHP to execute the binary using shell execution commands.

Can you log into your web hosting account and get a unix/linux prompt? If so, download cURL, compile it, and write your PHP script to execute the binary you just built.

For more information (and examples) of shell execution commands, check out:
  http://www.php.net/exec



Take care,

Nik
http://www.bigaction.org/
 
Old January 19th, 2004, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, keep in mind that $_POST is just an array in PHP. Granted, it's a special array, but it's still just an array that exists solely for the life of the currently executing script on your machine. Making any changes to variables in your scripts won't have ANY effect on ANY scripts you happen to redirect to, even if they're on the same site.

The only exception, of course, is writing to session variables, but that only persists data across the same host.


Take care,

Nik
http://www.bigaction.org/
 
Old January 19th, 2004, 03:31 PM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nik,
Thanks for your ideas. Unfortunately, this particular web host doesn't give command-line access -- can't get that UNIX prompt. I could try doing an exec of a shell command to see if it works, but I'm pretty certain that they have explicitly said it won't work.

I realize that $_POST is just a "local" array. My (admittedly poor) understanding of http, though, is that when a "type=POST" request is sent, the parameters are sent in the http-header body. The header body is otherwise empty. My thought (hope) was that perhaps there was some PHP array that could be set (like a $_POST_OUT) that would be copied into the http-header body, so when a redirect was done that data would be sent. It seems like an easy, and obvious, solution. But the fact that it doesn't seem to exist, and that it's apparently so hard to find a solution, means that I must be mistaken in my conceptual view of what would need to be done.

I'm still searching; I appreciate your taking the time to send your thoughts.
-don
 
Old January 19th, 2004, 08:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does your web host enable the socket functions of PHP? If so, you can connect to the other web server and assemble the HTTP request yourself. I spent a couple minutes snooping through the PHP manual for an example. There's a pretty simple one here:
  http://www.php.net/stream

Keep in mind that this uses the new streams library (err.. "extension") introduced in php 4.3.0. If your host is running an older version, you'll want to use the socket functions directly:
  http://www.php.net/sockets


I hate to give false hope, though -- I can't imagine that your web host would allowe these functions and disallow cURL. =(


Take care,

Nik
http://www.bigaction.org/
 
Old January 19th, 2004, 11:33 PM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nik,
I had not ever had a reason to work with sockets, and did not know to look at that part of the manual. The sample you pointed me to in the manual appears to do the trick. I've coded up a prototype and done some preliminary tests, and it appears that this will work. Thank you so much for your pointers, and for taking the time to help me.
-don
 
Old January 20th, 2004, 01:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm glad it's working!

Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using $_POST gkirk Beginning PHP 7 August 30th, 2006 07:21 AM
$_POST PROBLEM karlirvin PHP How-To 1 December 16th, 2005 03:14 AM
Getting nothing from $_POST['varName']; Kalisan Beginning PHP 10 February 3rd, 2005 02:37 PM
Getting nothing from $_POST['varName']; Kalisan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 January 26th, 2005 03:00 PM
$_POST Problem czambran BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 7 July 7th, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.