search
HomeBackend DevelopmentPHP Tutorial 怎么用cookie防止用户的灌水回复

如何用cookie防止用户的灌水回复?
今天没事瞎点 点到 凤凰网的一个链接了 http://yue.ifeng.com/y/detail_2011_12/07/11160676_0.shtml

评论框 内容是 :文明上网,登陆评论! 

直接点按钮 js alert 请填写评论内容 

再点一下文本框 文本框内容变成:请您先登录,再发布评论。

再点按钮 就提交了

打开的页面中的最新评论里就有了。然后我就复制了部分html

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->


<meta http-equiv="Content-Type" content="text/html" charset="utf-8">



提交了就有了。
然后想到用curl post 模拟form的效果 但是没试成功 可能是 少了一些东西
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
header("content-type:text/html;charset:utf-8;");
/*
chId    21202
content    mmmmmmmmm
docId    11160676
docName    吴卓羲女友张馨予家中大尺度内衣自拍照火辣曝光
docUrl    http://yue.ifeng.com/y/detail_2011_12/07/11160676_0.shtml
*/
  $url = "http://comment.ifeng.com/post.php";
   //$url = "http://localhost/php/index.php";
  $data = array(
    'content'=>'xxxxxxxxxxoooooooooooo',
    'docId'=>11160676,
    'docName'=>'吴卓羲女友张馨予家中大尺度内衣自拍照火辣曝光',
    'docUrl'=>'http://yue.ifeng.com/y/detail_2011_12/07/11160676_0.shtml',
    'chId'=>21202
);
 
$ret = http_post($url,$data);
var_dump($ret);

function http_post($url, $data)
 {
     $ch = curl_init();        
     curl_setopt($ch, CURLOPT_HEADER,1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     $data = http_build_query($data);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     
     curl_setopt($ch, CURLOPT_REFERER, "http://yue.ifeng.com/y/detail_2011_12/07/11160676_0.shtml");
     $cookie = "userid=1323532473389_2814";
     curl_setopt($ch, CURLOPT_COOKIE, $cookie);
     
     $rs = curl_exec($ch);
     curl_close($ch);
     return $rs;
 }



碰到的问题是:
1.评论的东西 人的头像跟其他不一样 是灰色的 正常的是银灰的。我换了浏览器 打开链接 没看到 灌水的内容 然后我用firebug 的firecookie插件看了一下 cookie 发现有 userid 和 cmtids 没灌水一个 cmtids 就多一个

http://comment.ifeng.com/view.php?doc_url=http%3A%2F%2Fyue.ifeng.com%2Fy%2Fdetail_2011_12%2F07%2F11160676_0.shtml&doc_name=%E5%90%B4%E5%8D%93%E7%BE%B2%E5%A5%B3%E5%8F%8B%E5%BC%A0%E9%A6%A8%E4%BA%88%E5%AE%B6%E4%B8%AD%E5%A4%A7%E5%B0%BA%E5%BA%A6%E5%86%85%E8%A1%A3%E8%87%AA%E6%8B%8D%E7%85%A7%E7%81%AB%E8%BE%A3%E6%9B%9D%E5%85%89&ishot=no

我清理cookie 刷新页面 cookie出现 userid = 1323533123324_5513
用上面的html提交一下 就出现 cmtids = 45583 再来一次 cmtids = 45583_45612
清理cookie 就没了 

2.为啥要暂存这样的评论呢?既然是要登录后才能评论。。。js没判断好到最新评论页显示了个假的?

小弟才疏学浅,没事瞎捣鼓了一下,望各位大侠帮忙分析一下。。。嘎嘎

------解决方案--------------------
刚去看了一下,还真是直接就提交了,这个网站也真是够宽松的……

如果 curl 直接提交不被接受的话,那很有可能服务器端还是有一些额外的要求(比如特定的 cookie 啥的),建议在网页提交的时候查看一下 HTTP 数据流,然后用 curl 模拟得充分一点,应该能搞定。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools