How to login with cURL and use regex

May 17, 2017, at 1:12 PM

This is my code. I don't know why its not working,everything seems fine maybe?

<form method="POST">
    <input name="link">
    <button type="submit">></button>
<title>GET IMG SRC</title>
if (!isset($_POST['link'])) exit();
$link = $_POST['link'];
echo '<div id="pin" style="float:center"><textarea class="text" cols="110" rows="50">';
function curl($link)
    //username and password of account
    $username = "";
    $password = "123";
    //set the directory for the cookie using defined document root var
    //$dir = DOC_ROOT."/ctemp";
    //build a unique path with every request to store 
    //the info per user with custom func. 
    //$path = build_unique_path($dir);
    //login form action url
    $postinfo = "username=".$username."&password=".$password;
    $cookie_file_path = "cookie.txt";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_URL, $link);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
    //set the cookie the site has for certain features, this is optional
    curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
    curl_setopt($ch, CURLOPT_USERAGENT,
        "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
    $get = curl($link);
    if (preg_match_all('/class="zoom" file="(.*?)"/', $get, $matches))
    // echoing contents
    foreach ($matches[1] as $content)
        echo $content."\r\n";
echo '</textarea>';

I want to use cURL to login to a page i submit in the form andthen use regex to the imagae src i want. Then the script export all the img url to the textarea !

Eloquent - Random from a existing list

Eloquent - Random from a existing list

I see that I can get a random row in Laravel 5 by:

convert multidimensional array to json format

convert multidimensional array to json format

I just started learning about JSONI have to create a static multidimensional array which later required to convert to json encode

Yii2 get data using hasMany relation

Yii2 get data using hasMany relation

I have a query $occupier that get all the ID (10 & 16) from the tableThe problem is how should I put it in the activeDataProvider query so that I can get all the ID that pass on since I cant do foreach loop inside the query

PHP/SQL - PHP won&#39;t output sql query

PHP/SQL - PHP won't output sql query

could you please help me? just trying to fill in some text as stackoverflow wants to write more text because it's all code