4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

php - curlに関して

Last updated at Posted at 2017-08-22

Login模擬

function login_post($url, $cookie, $post) {
     $curl = curl_init();//初始化curl
     curl_setopt($curl, CURLOPT_URL, $url);//目標URL
     curl_setopt($curl, CURLOPT_HEADER, 0);//Header表示するか
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);//レスポンスを表示するか
     curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //Cookieを設定し、指定したファイルに保存する
     curl_setopt($curl, CURLOPT_POST, 1);//postで送信
   //送信する中身
     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
     curl_exec($curl);//執行cURL
     curl_close($curl);//cURLを閉じる、メモリを解放
 }

Loginしたら、データを取る。


 function get_content($url, $cookie) {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //cookieを読み込み
     $rs = curl_exec($ch); //ページの内容を読み込み。
     curl_close($ch);
     return $rs;
 }

投稿します


 function post_thread($url, $cookie, $post)
 {
   $curl = curl_init();//初始化Curl
   curl_setopt($curl, CURLOPT_URL, $url);//送信先
   curl_setopt($curl, CURLOPT_HEADER, 0);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
   curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); //cookieを読み込む
   curl_setopt($curl, CURLOPT_POST, 1);//postで送信
   curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//送信の中身
   curl_exec($curl);//cURL執行
   curl_close($curl);
 }

##設定


 //postデータ
$post = array (
    'user_id' => '123456@qq.com',
    'password' => '123456',
    'goto_page' => 'http://m.app.cn/index.php',
    'act' => 'login',
    't' => time(),
);

//Loginアドレス
$url = "http://m.app.cn/account/login.php";

//cookie保存パスを設定
$cookie = dirname(__FILE__) . '/cookie_curl.txt';

//Login後、データを取る
$url2 = "http://m.app.cn/user/wap/my_index.php";

// メソードを呼び出して、模擬登録
 login_post($url, $cookie, $post);
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?