网站留言板的问题!!跪求大神帮忙!
最近我之前做的一个网站经常被人恶意留言,然后通过提交一些JS的代码来弹出一些乱七八糟的东西!求大神帮帮忙,我只是刚接触PHP这方面的工作,对一些安全的防范意识不是很好!看网上说用正则来替换!但是我对于正则表达式不懂!所以请大神懂得教下小弟,感激不尽!在这里,先感谢各位了!
------解决方案--------------------
网站在哪呢?我也去玩一下...
这种东西网上有很多的,可以充分的搜索。给你复制一段
用户输入的东西是不可信认的,例如,用户注册,用户评论等,这样的数据,你不光要做好防sql的注入,还要防止JS的注入,html的注入。
一,javascript注入的危害
举个简单的例子,我在一个网站留言了,并且这个网站没有对JS进行过滤,我在留言中加入以下内容
上面的代码虽然简单,可是可以无限循环,并且会一直弹东西出来,让人感觉很不爽,直到浏览器没有响应为止。浏览您网站的人,第一反应肯定是这个网站有病毒。
解决办法
$comment = preg_replace("//i",'',$comment);
把里面的javascript标签去掉就行了。
二,html注入的危害
1,容易引起页面错乱,对用户输入html标签不做处理的话,在读取的时候,很有可能就会破坏页面的布局。
2,影响seo,做seo的人都知道,pr高的网址,如果有链接,链到你的网站的话,可以加大自己网站的权重,这也是为什么有那么多人喜欢在高pr网站灌水的原因了。如果你没有对html标签进行处理的话,我输入以下内容
XXX.COM是个不河蟹网站,政府肯定会河蟹的,如果你的网站有链接到这样的网址,很有可能导致,你网站权重降低.
危害肯定不止这二个,因此要对这些html标签进行处理
$comment = preg_replace("/]*?>/si",'',$comment);
过滤的方法有好多,也可以直接把这样的符号转义掉,或者直接删除掉都是可以的。
------解决方案--------------------
把 内容中的 替换掉..
js端:
memo=留言内容;
memo=memo.replace('
服务端:
$memo=$_POST['memo'];
$memo=preg_replace('

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


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

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

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
