douxing6434 2014-11-17 11:27
浏览 53

UTF-8编码的字节顺序标记

Below is shown part of complete code:

<?php

    class Token
    {  public static function generate()
       {  return Session::put('token'), md5(uniqid()));
       }

       public static function check($token)
       { $tokenName = 'token';

         if(Session::exists($tokenName) && $token ===
Session::get($tokenName))
         { Session::delete($tokenName);  
           return true;
         }
         return false;
       }
    }
///////////////////////////////////////////////////////////////
      class Session
      {
         public static function exists($name)
         { return (isset($_SESSION[$name])) ? true : false;
         }

         public static function put($name, $value)
         { return $_SESSION[$name] = $value;
         }

         public static function get($name)
         { return $_SESSION[$name];
         }

         public static function delete($name)
         { if(self::exists($name))
           { unset($_SESSION[$name]);
           }
         }
///////////////////////////////////////////////////////////////
    class Input
    {  
       public static function get($item)
       { if(isset($_POST[$item]))
         { return $_POST[$item];
         }
         return '';
       }
    }
//////////////////////////////////////////////////////////////

   if(isset($_POST['username']) && isset($_POST['password']))
   { if(Token::check(Input::get('token')))
     { $validate = new Validate();

       $validation = ................;

       if($validation->passed())
       { $user = new User();

         $login = $user->login(Input::get('username'),
Input::get('password'));

         if($login)
         { echo 'Success';
           Redirect::to('index.php');
         }
         else
         { echo 'Sorry, login failed!';
         }
       }     //validation passed
       else
       { foreach($validation->errors() as $error)
         { echo $error, '<br>';
         }
         echo "<script> setTimeout(\"location.href =
'index.php';\",30000); </script>";
       }
     }
   }
?>

<form action="" method="POST">
<P>
  <label for="username">Username</label>
  <input type="text" name="username" id="username"

autocomplete="off">
</P>
<P>
  <label for="password">Password</label>
  <input type="password" name="password" id="password"

autocomplete="off">
</P>
<P>
  <input type="hidden" name="token" value="<?php echo

Token::generate(); ?>">
  <input type="submit" value="LOG IN">
</P>
</form>

When I do following:

       public static function check($token)
       { $tokenName = Config::get('session/token_name');
         $testing = Session::get($tokenName);
echo join(' ', array_map(function($c) { return sprintf('%02x', $c); }, array_map('ord', str_split($token))));
echo "<br>";
echo join(' ', array_map(function($c) { return sprintf('%02x', $c); }, array_map('ord', str_split($testing))));

         if(Session::exists($tokenName) && $token === Session::get($tokenName))
         { Session::delete($tokenName);  
           return true;
         }
         return false;
       }
    }

I get:

ef bb bf ef bb bf ef bb bf 39 31 64 32 61 66 63 31 63 61 38 63 39 32 39 66 62 63 63 35 35 61 36 38 37 31 65 36 37 33 65 61

and:

39 31 64 32 61 66 63 31 63 61 38 63 39 32 39 66 62 63 63 35 35 61 36 38 37 31 65 36 37 33 65 61

which does not satisfy condition:

$token === Session::get($tokenName)

I have used:

<form action="" method="POST" accept-charset="utf-8">

but that did not work. All I know is that it has something to do with UTF-8 encoded Byte-Order-Marks but I don't know how to remove the extra bytes. Any suggestions as to how I can solve this problem? I'm using PHP Version 5.5.12

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题