حل شده

وارد شدن به یک سایت با curl در php

بازدید31kپست ها2آخرین فعالیت5 سال پیش
0
3

سلام دوستان عزیز
به کدی نیاز دارم بتونم با curl بتونم وارد یک سایت بشم
یعنی یک سایت لاگین بشم و بتونم به صفحه داشبورد پنل کاربری دسترسی داشته باشم
مثلا وارد جیمیل بشم با curl و بتونم تمامی ایمیل هارو دریافت کنم وو بگیرم
حالا فقط جیمیل نه هر سایتی
لطفا کمکم کنین ممنون میشم

2 پاسخ

0

سلام

همین کدی که دوست عزیزم براتون گذاشتن با کمیویرایش میتونید ازشبرای لاگین تو irdevs استفاده کنید. باید تو هر مرحله تست کنید و مطمئن بشید که کد شما بدرستی کار میکنه.

<?php

define("DOC_ROOT","curl");
//username and password of account
$username = 'username';
$password = 'passwd';

//set the directory for the cookie using defined document root var
$path = DOC_ROOT."/ctemp";
//build a unique path with every request to store. the info per user with custom func. I used this function to build unique paths based on member ID, that was for my use case. It can be a regular dir.
//$path = build_unique_path($path); // this was for my use case

//login form action url
$url="https://www.irdevs.com/member.php"; 
$postinfo = "username=".$username."&password=".$password . '&action=do_login&submit';

$cookie_file_path = $path."/cookie.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);

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, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);

curl_setopt($ch, CURLOPT_VERBOSE, true);

$html = curl_exec($ch);
//after login html
echo $html;

//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, "https://www.irdevs.com");
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);

echo $html;
curl_close($ch);

برای تست یوزر و پسورد تو متغیرهای خواسته شده وارد کنید تا نتیجه رو ببینید.

0

سلام از این کد میتونید استفاده بکنید: هر جا نیازه تغییرش بدید

define("DOC_ROOT","/path/to/html");
//username and password of account
$username = trim($values["email"]);
$password = trim($values["password"]);

//set the directory for the cookie using defined document root var
$path = DOC_ROOT."/ctemp";
//build a unique path with every request to store. the info per user with custom func. I used this function to build unique paths based on member ID, that was for my use case. It can be a regular dir.
//$path = build_unique_path($path); // this was for my use case

//login form action url
$url="https://www.example.com/login/action"; 
$postinfo = "email=".$username."&password=".$password;

$cookie_file_path = $path."/cookie.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
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);
curl_exec($ch);

//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/page/");
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
curl_close($ch);
با این کد توی سایتی که میخواستم تست کردم ولی نشد شما میتونین یک سایتی رو مدنظرتون بگیرین و بهم بگین که تو اون سایت برم و تست کنم چون بدونم کد اوکی هست مشکلاتشو برطرف میکنم – mrprogrammer32 5 سال پیش

سوال برنامه نویسی دارید؟

ندونستن عیب نیست، نپرسیدن چرا!

خوش آمدید

برای طرح سوال، ایجاد بحث و فعالیت در سایت نیاز است ابتدا وارد حساب کاربری خود شوید. در صورتی که هنوز عضو سایت نیستید میتوانید در عرض تنها چند ثانیه ثبت نام کنید.