Skip to content

Instantly share code, notes, and snippets.

View veb's full-sized avatar
👋

Mike Mackenzie veb

👋
View GitHub Profile
@veb
veb / curlexists.php
Created September 10, 2015 17:19
articles-12
<?php
# ...
$ch = curl_init();
if($ch){
# ...
@veb
veb / headers.php
Last active September 10, 2015 17:16
articles-11
<?
// original curl request up here
if ($headers['http_code'] == 302){
$ch = @curl_init();
curl_setopt($ch, CURLOPT_URL, $headers['redirect_url']);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); // set cookie file to given file
@veb
veb / curl_exec.php
Created September 10, 2015 17:13
articles-10
<?
# ...
$content = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
@veb
veb / curl_set.php
Created September 10, 2015 17:12
articles-9
<?php
# ...
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); // set cookie file to given file
@veb
veb / curl-1.php
Created September 10, 2015 17:10
articles-8
<?php
# ...
$url = 'http://www.website.com/login.php';
$postdata = array('username' => "Jamie", 'password' => "password");
# ...
?>
@veb
veb / codeigniter-curl.php
Created September 10, 2015 17:00
articles-7
<?php
$url = 'http://www.website.com/login.php';
$postdata = array('username' => "Jamie",'password' => "password");
$ch = curl_init();
if($ch){
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
@veb
veb / xpath-index3.php
Created September 10, 2015 16:56
articles-6
<?php
$dom = new DOMDocument();
@$dom->loadHTML($content);
$tempDom = new DOMDocument();
$xpath = new DOMXPath($dom);
$container = $xpath->query("//div[@id='container']");
foreach ( $container as $item ) {
$tempDom->appendChild($tempDom->importNode($item,true));
@veb
veb / index3.html
Created September 10, 2015 16:55
articles-5
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="container">
<div id="person">
<p>Bob</p>
<p>25</p>
<p>180lbs</p>
@veb
veb / leftDiv.php
Created September 10, 2015 16:54
articles-4
<?php
// $content is the content you scraped (via curl for example)
$dom = new DOMDocument();
@$dom->loadHTML($content)
$xpath = new DOMXPath($dom);
$imgSrc = $xpath->query("//html/body/div[1]/div[1]/img/@src");
@veb
veb / index2.html
Created September 10, 2015 16:53
articles-3
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<div>
<p class="bodyText">This is left</p>
<img src="images/test.jpg" />
</div>