高手请进,curl模拟登陆的问题
我想要做一个模拟登陆,可是一般网站有表单提交的都可以模拟登陆成功
就是另一些网站,比如速卖通(https://login.aliexpress.com/)
我的代码是这写的
function vlogin($url,$request){
$cookie_jar = tempnam('./tmp','cookie');//在当前目录下生成一个随机文件名的临时文件
$ch = curl_init(); //初始化curl模块
curl_setopt($ch,CURLOPT_URL,$url);//登录页地址
curl_setopt($ch, CURLOPT_POST, 1);//post方式提交
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);//要提交的内容
//把返回$cookie_jar来的cookie信息保存在$cookie_jar文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
//设定返回的数据是否自动显示
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//设定是否显示头信息
curl_setopt($ch, CURLOPT_HEADER, false);
//设定是否输出页面内容
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_exec ($ch);
curl_close($ch); //get data after login
return $cookie_jar;
}
//登录成功后通过cookies获取页面内容
function get_content_by_cookie($url,$cookie_jar){
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$orders=curl_exec($ch2);
curl_close($ch2);
return $orders;
}
function clear_cookie($cookie_tmp_name){
@unlink($cookie_tmp_name);
}
$list_url='http://cn.ae.alibaba.com/index.htm';
$login_url='https://login.aliexpress.com/';
$post_data='pd=aliexpress&xloginPassport=******&xloginPassword=******';
$cookie_file=vlogin($login_url,$post_data);
$tmp_curl=get_content_by_cookie($list_url,$cookie_file);
echo $cookie_file;
echo $tmp_curl;
//clear_cookie($cookie_file);
?>
可是登陆不成功,感觉应该是 $login_url 错了,速卖通里既然是不通过form提交的,我JS基础不是很好,看不懂他的代码,求高手提点下!
感谢啊!
------解决方案--------------------
你可以改改你得vlogin函数,察看返回头+body
function vlogin($url,$request){<br> $cookie_jar = tempnam('./tmp','cookie');//在当前目录下生成一个随机文件名的临时文件<br> $ch = curl_init(); //初始化curl模块 <div class="clear"> </div>

tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

phpisusedforsenderemailsduetoitsbuilt-inmail()函數andsupportivelibrariesLikePhpMailerAndSwiftMailer.1)usethemail()functionForbasiceMails,butithasimails.2)butithasimail.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显著提升PHP应用的性能。

依賴性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增強量強制性,可驗證性和MATIALWINABIOS.ItallowSpasspassingDepentenciesLikEdenciesLikedAbaseConnectionStoclasseconnectionStoclasseSasasasasareTers,interitationAseTestingEaseTestingEaseTestingEaseTestingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。