Solved

using "sockets" or "scraping" in php

Posted on 2008-10-14
3
445 Views
Last Modified: 2013-12-13
I have heard that it is possible to log into other sites using php on a server...i've seen it referred to as scraping or opening a socket, neither of which I am familiar with (not sure if they're the same thing)

to clarify, i want to automate certain processes that take waaay to long to do manually...
so, i want to:

1. open a connection with a website (let's say Paypal)
2. enter my username and password and "click" the submit button
3. go to the "send payments" page
4. enter all the required info for a payment (taken from my database)
5. submit the payment form
6. repeat from step 3 for the next row in my database

I want to do all of this using php (preferably set up as a CRON job)

is this possible?
can i see a sample script?
how are cookies/sessions handled?

0
Comment
Question by:sjamal_hsj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 22723338
There are many ways to achieve this.

Personally, with a site like PayPal, I would go down their developers API route. Far safer and supported.

For other sites, which don't require security, you can use functions like file_get_contents() to read a page.

If you need more advanced GETting and POSTing, then you can use cURL, sockets or stream_contexts (my preference).

With a stream_context, you setup things like protocol, cookies, etc. for your communication to site x. THen all comms (using normal file_get_contents() again) take with the request the cookies or POSTed data or even file uploads.

But, for sites like PayPal, use their API.
0
 

Author Comment

by:sjamal_hsj
ID: 22734448
so, with stream_context, can you show me a quick sample script of how you would set up the post variables and then submit them to a site?

as an example, lets say the site uses the form i've included as a code snippet

also, once i log in using stream_context, my file_get_contents() will then return the page for a logged in user?
<form name="login" action="login.php" method="post">
  <input type="text" name="username" id="user" /><br>
  <input type="password" name="pwd" id="pwd1" /><br>
  <input type="submit" name="submitBtn" value="Login" />
</form>

Open in new window

0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22738635
Something like this ...
<?php
$data = array ('username' => 'some_username', 'pwd' => 'some_pwd', 'submitBtn' => 'Login');
$data = http_build_query($data);
 
$context_options = array (
        'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
                . "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data
            )
        );
 
$context = context_create_stream($context_options)
$HTML = file_get_contents('http://url', FILE_BINARY, $context);
?>

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question