Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // _____ _ _ _ _
- // | ___|__ _ __ _ __ ___ (_)_ __ _ __ _ _| |_ | |__ ___ | |_
- // | |_ / _ \| '__| '_ ` _ \ | | '_ \| '_ \| | | | __| | '_ \ / _ \| __|
- // | _| (_) | | | | | | | | | | | | | |_) | |_| | |_ | |_) | (_) | |_
- // |_| \___/|_| |_| |_| |_| |_|_| |_| .__/ \__,_|\__| |_.__/ \___/ \__|
- // __ ___ _ _ ____ ___|_|____ _____ _
- // \ \ / (_) |_| |__ / ___/ ___|| _ \| ___| | |__ _ _ _ __ __ _ ___ ___
- // \ \ /\ / /| | __| '_ \ | | \___ \| |_) | |_ | '_ \| | | | '_ \ / _` / __/ __|
- // \ V V / | | |_| | | | | |___ ___) | _ <| _| | |_) | |_| | |_) | (_| \__ \__ \
- // \_/\_/ |_|\__|_| |_| \____|____/|_| \_\_| |_.__/ \__, | .__/ \__,_|___/___/
- // by Erik Keresztes (fiverr.com/erik_keresztes) |___/|_|
- function getStringBetween($string, $start, $end)
- {
- $string = ' ' . $string; // add space to start of string
- // find ending position of $start
- $startpos = strpos($string, $start);
- if (!$startpos) return ''; // if can't find $start in $string return empty string
- $startpos += strlen($start);
- // get length between $start and $end
- $length = strpos($string, $end, $startpos) - $startpos;
- return substr($string, $startpos, $length);
- }
- $url = 'redacted';
- $cookies = realpath('cookies.txt');
- $userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36';
- // FIRST REQUEST (to get the token)
- $ch = curl_init(); // open connection
- // set curl options
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // execute request and get webpage source
- $result = curl_exec($ch);
- curl_close($ch); // close connection
- // get CSRF token from webpage source
- $token = getStringBetween($result, '<meta name="csrf-token" content="', '">');
- // SECOND REQUEST
- // set POST variables
- $fields = array(
- '_token' => $token,
- 'type' => 'unknown',
- 'rating' => 5,
- 'comment' => 'This is a test'),
- 'name' => 'POST bot'
- );
- // build the urlencoded data
- $postfields = http_build_query($fields);
- $ch = curl_init(); // open curl connection
- // set curl options
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_exec($ch); // execute post
- curl_close($ch); // close connection
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement