Sessions

To reuse the same proxy for multiple requests, simply use the session_number parameter by setting it equal to a unique integer for every session you want to maintain (e.g. session_number=123). This will allow you to continue using the same proxy for each request with that session number. To create a new session simply set the session_number parameter with a new integer to the API. The session value can be any integer. Sessions expire 15 minutes after the last usage.

  • API REQUEST

<?php
$url = "http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&session_number=123";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
  • PROXY MODE

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://httpbin.org/ip");
curl_setopt($ch, CURLOPT_PROXY, "http://scraperapi.session_number=123:APIKEY@proxy-server.scraperapi.com:8001");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
  • SDK Method

# remember to install the library: composer require scraperapi/sdk
<?php
  $client = new ScraperAPIClient("APIKEY");
  $result = $client->get("http://httpbin.org/ip", ["session_number" => 123])->raw_body;
  print($result);

Last updated