[PHP] Re: talking to a web page
You can use PEAR's HTTP_Client package (http://pear.php.net/package/HTTP_Client) to connect to a website, do authentication, post forms, handle redirects, etc. It also keeps track of cookies. Here's a sample (note that the URLs in this will probably not work): require_once('HTTP/Client.php'); $client = new HTTP_Client(array('user' = 'username', 'password' = 'password')); $code = $client-post('http://www.example.com/script.asp', array('var1' = 'val1', 'VAR2' = 'val2')); $code = $client-get('http://www.example.com/loginRequired.php'); David T-G wrote: Hi, all -- My host has written a control panel to handle all site management needs, and it's great except that there's no back-end hook that I can use to create a new site or user once I have collected my input and verified my payment in my own pages. I obviously don't want to have to do all of the site creations by hand; that's why we have computers :-) At this point I could either figure out all of the steps for creating a site -- there are, to my knowledge so far, DB tables to update, dirs to make, other files to update, and apache to restart -- or figure out how to talk to the control panel from a script. With nearly fifteen years of SysAdmin background but only a few years of PHP background, I know which I think is probably easier or at least quicker :-) but I don't want to miss any little things that their interface does that will bite me in the tail later. The control panel requires authentication and a cookie and then a few clicks to get to the fill-ins, so I imagine that I could just construct that form and hand it off -- except for the login authentication part. Which route would y'all take, and (more importantly) which would you recommend to someone at my capable-but-not-expert level? Remember that I'll come back to the list when I get stumped ;-) TIA HAND :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: talking to a web page
Justin, et al -- ...and then Justin Patrin said... % % You can use PEAR's HTTP_Client package % (http://pear.php.net/package/HTTP_Client) to connect to a website, do % authentication, post forms, handle redirects, etc. It also keeps track % of cookies. Oh, goodie; that sounds great. % % Here's a sample (note that the URLs in this will probably not work): % % require_once('HTTP/Client.php'); % $client = new HTTP_Client(array('user' = 'username', 'password' = % 'password')); That certainly seems easy enough. % $code = $client-post('http://www.example.com/script.asp', % array('var1' = 'val1', % 'VAR2' = 'val2')); OK, so I don't actually need to navigate the page but instead just fill in the fields and then send it. Very cool. % $code = $client-get('http://www.example.com/loginRequired.php'); Now to figure out how to try it out :-) Thanks HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP] Re: talking to a web page
One last thing. If all you need to do is go to a page and not navigate it, you could just use HTTP_Request, upon which HTTP_Client is built. Then again, if you have multiple request to do and have to keep sending the auth data, the Client would be best. David T-G wrote: Justin, et al -- ...and then Justin Patrin said... % % You can use PEAR's HTTP_Client package % (http://pear.php.net/package/HTTP_Client) to connect to a website, do % authentication, post forms, handle redirects, etc. It also keeps track % of cookies. Oh, goodie; that sounds great. % % Here's a sample (note that the URLs in this will probably not work): % % require_once('HTTP/Client.php'); % $client = new HTTP_Client(array('user' = 'username', 'password' = % 'password')); That certainly seems easy enough. % $code = $client-post('http://www.example.com/script.asp', % array('var1' = 'val1', % 'VAR2' = 'val2')); OK, so I don't actually need to navigate the page but instead just fill in the fields and then send it. Very cool. % $code = $client-get('http://www.example.com/loginRequired.php'); Now to figure out how to try it out :-) Thanks HAND :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: talking to a web page
Justin, et al -- ...and then Justin Patrin said... % % One last thing. If all you need to do is go to a page and not navigate % it, you could just use HTTP_Request, upon which HTTP_Client is built. That sounds even better; I'm only going to be dealing with a couple of pages. % Then again, if you have multiple request to do and have to keep sending % the auth data, the Client would be best. I'll try either both. I'm having some trouble getting started, though... I surfed over to pear.php.net, found and downloaded both (yikes, Client is only a 0.2 release :-) and opened them up. I made /usr/local/lib/php/HTTP and then copied each's contents in there (well, the docs/ over to the lib docs file), so I now have /usrlocal/lib/php/HTTP/Client.php /usrlocal/lib/php/HTTP/Client/CookieManager.php /usrlocal/lib/php/HTTP/Client/Listener.php and similar for HTTP_Request but when I run a simple echo ?php require_once('HTTP/Client.php') ; print 'done';? |php -q I get back Failed opening required 'HTTP/Client.php' :-( Is there a different install procedure? TIA HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP] Re: talking to a web page
Well, technically, you should be using the PEAR installer script to install PEAR packages. http://pear.php.net/manual/en/installation.php Barring that, you can make yourself a PEAR directory somewhere and add it to your include_path in your php.ini. Also note that you have to have all of the dependencies for those packages. Easiest way to go is to use the PEAR installer if you're just getting started. David T-G wrote: Justin, et al -- ...and then Justin Patrin said... % % One last thing. If all you need to do is go to a page and not navigate % it, you could just use HTTP_Request, upon which HTTP_Client is built. That sounds even better; I'm only going to be dealing with a couple of pages. % Then again, if you have multiple request to do and have to keep sending % the auth data, the Client would be best. I'll try either both. I'm having some trouble getting started, though... I surfed over to pear.php.net, found and downloaded both (yikes, Client is only a 0.2 release :-) and opened them up. I made /usr/local/lib/php/HTTP and then copied each's contents in there (well, the docs/ over to the lib docs file), so I now have /usrlocal/lib/php/HTTP/Client.php /usrlocal/lib/php/HTTP/Client/CookieManager.php /usrlocal/lib/php/HTTP/Client/Listener.php and similar for HTTP_Request but when I run a simple echo ?php require_once('HTTP/Client.php') ; print 'done';? |php -q I get back Failed opening required 'HTTP/Client.php' :-( Is there a different install procedure? TIA HAND :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PEAR installations (was Re: [PHP] Re: talking to a web page)
Justin, et al -- ...and then Justin Patrin said... % % Well, technically, you should be using the PEAR installer script to % install PEAR packages. http://pear.php.net/manual/en/installation.php Oh. Oops :-) % % Barring that, you can make yourself a PEAR directory somewhere and add % it to your include_path in your php.ini. Well, I already have PEAR (and some modules), it appears: bash-2.05a$ ls -lFd /usr/local/lib/php/PEAR drwxr-xr-x 4 root wheel 512 Oct 25 2002 /usr/local/lib/php/PEAR/ So what I suppose I need to learn is now to install PEAR modules from there. Aha! I see /usrlocal/bin/pear :-) OK. Server 1: FreeBSD 4.5-RELEASE, PHP 4.2.3 (I think) bash-2.05a$ sudo pear install HTTP_Client HTTP_Request br / bFatal error/b: Failed opening required 'PEAR.php' (include_path='.:') in b/usr/local/bin/pear/b on line b27/bbr / Server 2: FreeBSD 4.8-RELEASE, PHP 4.3.3rc1 (I think) bash-2.05a$ sudo pear install HTTP_Client HTTP_Request For this remote PEAR operation you need to install the XML_RPC package bash-2.05a$ sudo pear install XML_RPC HTTP_Client HTTP_Request downloading XML_RPC-1.0.4.tgz ... Starting to download XML_RPC-1.0.4.tgz (11,991 bytes) .done: 11,991 bytes bash-2.05a$ sudo pear install HTTP_Client HTTP_Request For this remote PEAR operation you need to install the XML_RPC package It looks like my include_path is messed up on server1; I'll look into that. I've no idea what's up with server2, though; I DID install the XML_RPC package % % Also note that you have to have all of the dependencies for those % packages. Easiest way to go is to use the PEAR installer if you're just % getting started. I'd love to :-) Please forgive me; I only know from perl -MCPAN -e shell and away I go :-) Thanks again HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature