Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on code from this page:</p> <p><a href="https://stackoverflow.com/questions/8991873/login-to-google-with-php-and-curl-cookie-turned-off">Login to Google with PHP and Curl, Cookie turned off?</a></p> <pre><code>function createAlert($search) { $USERNAME = 'EMAIL_ADDRESS'; $PASSWORD = 'PASSWORD'; $COOKIEFILE = 'cookies.txt'; $ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEFILE); curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIEFILE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLogin?hl=en&amp;service=alerts&amp;continue=http://www.google.com/alerts/manage'); $data = curl_exec($ch); $formFields = $this-&gt;getFormFields($data); $formFields['Email'] = $USERNAME; $formFields['Passwd'] = $PASSWORD; unset($formFields['PersistentCookie']); $post_string = ''; foreach($formFields as $key =&gt; $value) { $post_string .= $key . '=' . urlencode($value) . '&amp;'; } $post_string = substr($post_string, 0, -1); curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); $result = curl_exec($ch); if (strpos($result, '&lt;title&gt;Redirecting') === false) { var_dump($result); die("Login failed"); } else { curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts'); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, null); $result = curl_exec($ch); // Create alert preg_match('/&lt;input type="hidden" name="x" value="([^"]+)"/', $result, $matches); $post = array( "x" =&gt; $matches[1], // anti-XSRF key "q" =&gt; $search, // Search term "t" =&gt; 7, // Result type (everything) "f" =&gt; 1, // Frequency (once a day) "l" =&gt; 1, // How many (all results) "e" =&gt; "feed" // Type of delivery (RSS) ); $post_string = ''; foreach($post as $key =&gt; $value) { $post_string .= $key . '=' . urlencode($value) . '&amp;'; } $post_string = substr($post_string, 0, -1); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts/create'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); $result = curl_exec($ch); $matches = array(); preg_match('#&lt;a href="(http://www.google.com/alerts/feeds/[\d/]+)"#', $result, $matches); $top_alert = $matches[1]; return $top_alert; } } function getFormFields($data) { if (preg_match('/(&lt;form.*?id=.?gaia_loginform.*?&lt;\/form&gt;)/is', $data, $matches)) { $inputs = $this-&gt;getInputs($matches[1]); return $inputs; } else { die("didn't find login form"); } } function getInputs($form) { $inputs = array(); $elements = preg_match_all('/(&lt;input[^&gt;]+&gt;)/is', $form, $matches); if ($elements &gt; 0) { for($i = 0; $i &lt; $elements; $i++) { $el = preg_replace('/\s{2,}/', ' ', $matches[1][$i]); if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) { $name = $name[1]; $value = ''; if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) { $value = $value[1]; } $inputs[$name] = $value; } } } return $inputs; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload