curl 远程登录 以及远程发贴有关问题
curl 远程登录 以及远程发贴问题
http://www.czhi-fi.com/bbsxp/ 论坛 是个bbsxp论坛系统的 是5.15版本。
我用snoopy可以远程登录并发贴。而用curl却无法实现远程登录,更不要说远程发贴了。
我很想用curl实现模拟登录,恳请高手赐教!!拜谢!!
说明:
登录地址:http://www.czhi-fi.com/bbsxp/login.asp
用户名 :mytest
密 码 :111111
首先把我成功用snoopy远程登录并发贴的代码公开:
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $url = "http://www.czhi-fi.com/bbsxp/"; //论坛地址 $url1 = "http://www.czhi-fi.com/bbsxp/default.asp"; //源地址 $url2 = "http://www.czhi-fi.com/bbsxp/login.asp"; //登录提交判断页 $posts = array(); $posts['menu'] = 'add'; $posts['url'] = $url1 ; $posts['username'] = 'mytest'; $posts['userpass'] = '111111'; include("Snoopy.class.php"); $snoopy = new Snoopy; $snoopy->submit($url2,$posts); //模拟浏览器提交并取得返回结果 /*下面是发贴*/ $url3 = "http://www.czhi-fi.com/bbsxp/newtopic.asp"; //发贴提交页面。 $topic = '经典笑话:离婚'; //标题 $content = '丈大:“孩子他娘。咱们离婚好吗?” 妻子:“咱们从来下吵不闹,为什么要离婚?” 丈夫:“我的意思是,离婚以后我再和你结婚。” 妻子:“啊、你今天发神经疯了还是怎么着?” 丈夫:“没有啊!你看,这几年年轻人结婚,把我的腰包都掏空了,如果我们不再结一次婚,这些践怎么捞得回来哟?'; $posts = array(); $posts['forumid'] = '16'; //板块id号 这个是灌水板块 $posts['topic'] = $topic ; //标题 $posts['content'] = $content ; //内容 $snoopy->submit($url3,$posts); //模拟浏览器提交并取得返回结果 //print_r($snoopy->results); $content = $snoopy->results ; //http://www.czhi-fi.com/bbsxp/ShowPost.asp?id=3148 //ShowForum.asp?forumid=16 if(preg_match("/\"(\d+)\",\"[^\r\n\"]*?\",\"[^\r\n\"]*?\",\"mytest\"/is",$content, $matches)){ if(!empty($matches[1])){ $out = $url . "ShowPost.asp?id=".$matches[1] ; }else{ $out = "没有采集到刚发贴的地址,<a href="%5C%22%22.%24url.%22ShowForum.asp?forumid=16%5C%22" target='\"_blank\"'>查看此板块内有没有新发贴</a>"; } }else{ $out = "发贴可能失败了,<a href="%5C%22%22.%24url.%22ShowForum.asp?forumid=16%5C%22" target='\"_blank\"'>查看此板块内有没有新发贴</a>"; } echo "<a href="%5C%22%24out%5C%22" target='\"_blank\"'>".$out."</a>" ;
*************************************
下面是我的curl登录代码,这个代码不能实现远程登录,请高人指点!
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $login_url = "http://www.czhi-fi.com/bbsxp/login.asp";//登录页地址 $source_url = "http://www.czhi-fi.com/bbsxp/default.asp";//源页地址 $post_fields = array(); //以下两项固定值 $post_fields['menu'] = 'add'; $post_fields['url'] = 'http://www.czhi-fi.com/bbsxp/Default.asp'; //用户名和密码,必须填写 $post_fields['username'] = "mytest"; $post_fields['userpass'] = "111111"; $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_REFERER, $source_url); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 允许自动跳转 $contents = curl_exec($ch); curl_close($ch); echo $contents ;
我很想用curl实现模拟登录,恳请高手赐教!!拜谢!!
------解决方案--------------------
cookie得获取(http 返回头中的set-Cookie项)并反馈过去(http请求头中的cookie项)。
- PHP code
$login_url = "http://www.czhi-fi.com/bbsxp/login.asp";//登录页地址 $source_url = "http://www.czhi-fi.com/bbsxp/default.asp";//源页地址 $post_fields = array(); //以下两项固定值 /*$post_fields['menu'] = 'add'; $post_fields['url'] = 'http://www.czhi-fi.com/bbsxp/Default.asp'; //用户名和密码,必须填写 $post_fields['username'] = "mytest"; $post_fields['userpass'] = "111111";*/ $cookie="cookie.txt"; $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_REFERER, $source_url); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=mytest&userpass=111111&menu=add&url=http://www.czhi-fi.com/bbsxp/Default.asp'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 允许自动跳转 $contents = curl_exec($ch); curl_close($ch); echo $contents; <div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

How to handle 301 redirection of web pages in PHPCurl? When using PHPCurl to send network requests, you will often encounter a 301 status code returned by the web page, indicating that the page has been permanently redirected. In order to handle this situation correctly, we need to add some specific options and processing logic to the Curl request. The following will introduce in detail how to handle 301 redirection of web pages in PHPCurl, and provide specific code examples. 301 redirect processing principle 301 redirect means that the server returns a 30

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

HTTP status code 403 means that the server rejected the client's request. The solution to http status code 403 is: 1. Check the authentication credentials. If the server requires authentication, ensure that the correct credentials are provided; 2. Check the IP address restrictions. If the server has restricted the IP address, ensure that the client's IP address is restricted. Whitelisted or not blacklisted; 3. Check the file permission settings. If the 403 status code is related to the permission settings of the file or directory, ensure that the client has sufficient permissions to access these files or directories, etc.

Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files With the development of the Internet, the file download function has become one of the basic needs of many websites and applications. For scenarios where multiple files need to be downloaded at the same time, the traditional synchronous download method is often inefficient and time-consuming. For this reason, using PHP to download multiple files asynchronously over HTTP has become an increasingly common solution. This article will analyze in detail how to use PHP asynchronous HTTP through an actual development case.
