加入收藏 | 设为首页 | 会员中心 | 我要投稿 成都站长网 (https://www.028zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长资讯 > 评论 > 正文

浅谈PHP安全规范

发布时间:2018-10-14 12:35:28 所属栏目:评论 来源:littlepotato
导读:副标题#e# 【新品产上线啦】51CTO播客,随时随地,碎片化学习 一、前言 php因天生支持web应用的开发,以其简单易学,开发效率高而备受喜爱。使其占据了大片的市

Low level

  1. <?php  
  2.  
  3. // Is there any input?  
  4. if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {  
  5.     // Feedback for end user  
  6.     echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';  
  7. }  
  8.  
  9. ?>  

Medium level

  1. <?php  
  2.  
  3. // Is there any input?  
  4. if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {  
  5.     // Get input  
  6.     $name = str_replace( '<script>', '', $_GET[ 'name' ] );  
  7.  
  8.     // Feedback for end user  
  9.     echo "<pre>Hello ${name}</pre>";  
  10. }  
  11.  
  12. ?>  

High level

  1. <?php  
  2.  
  3. // Is there any input?  
  4. if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {  
  5.     // Get input  
  6.     $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $_GET[ 'name' ] ); 
  7.  
  8.     // Feedback for end user  
  9.     echo "<pre>Hello ${name}</pre>";  
  10. }  
  11.  
  12. ?>  

Impossible level

  1. <?php  
  2.  
  3. // Is there any input?  
  4. if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {  
  5.     // Check Anti-CSRF token  
  6.     checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );  
  7.  
  8.     // Get input  
  9.     $name = htmlspecialchars( $_GET[ 'name' ] );  
  10.  
  11.     // Feedback for end user  
  12.     echo "<pre>Hello ${name}</pre>";  
  13. }  
  14.  
  15. // Generate Anti-CSRF token  
  16. generateSessionToken();  
  17.  
  18. ?> 

(编辑:成都站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读