PDA

View Full Version : شبیه سازی کامل مرورگر



sina365
چهارشنبه 14 بهمن 1394, 12:46 عصر
<?php




$header = array('Host: mail.Example.com'
,'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:42.0) Gecko/20100101 Firefox/42.0','Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language: fa-IR,fa;q=0.8,en-US;q=0.5,en;q=0.3','Accept-Encoding: gzip, deflate','Cookie: JSESSIONID=******* ','Referer: https://mail.example.ir/login','Connection: keep-alive');










$postfields = array();

$postfields["username"] = "sina365";
$postfields["password"] = "•••••••••••••••• ••••••••••";



$agent= 'Mozilla/5.0 (Windows NT 6.1; rv:42.0) Gecko/20100101 Firefox/42.0';
$url = "https://mail.example/login";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL,$url);
$result= curl_exec($ch);
echo $result;
?>


Cookie: JSESSIONID= برابر چیه؟
می تونم همون چیزی که خود مرور گر ارسال می کنه رو بزارم بجاش؟
فرق این دوتا چیه و کدوم بهتره؟
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, $header);
وقتی که توی هدر یک بار user agent را تعریف کردیم به کد زیر نیازی هست؟
//curl_setopt($ch, CURLOPT_USERAGENT, $agent);

با همه ی این اوصاف خروجی اینه:

HTTP/1.1 100 Continue

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=*****************; Path=/; Secure; HttpOnly
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
Transfer-Encoding: chunked
Vary: Accept-Encoding
Date: Wed, 03 Feb 2016 09:43:48 GMT
Connection: close






<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
</head>

<body class="bd2">
<div id="doc2" class="main yui-t7">
<div id="bd" class="err_container">
<div class="yui-g err_panel-top">
<div class="yui-u first input-col">
<div id="logo"></div>
</div>
<div class="yui-u">
<div id="err_text">
در حال حاضر سرویس مورد نظر در دسترس نمیباشد، لطفا بعدا تلاش بفرمائید
</div>