我是把数组序列化之后存入数据库的某个字段,但是数组中有些数据的值带有特殊字符,如图:
保存在数据库之后就成这样子了
类似这样的特殊字符还有很多的;
丢失了一部分数据,哪位哥哥遇到过这种情况吗?请赐教。
回复讨论(解决方案)
什?特殊字符,把字符串base64_encode後?出?看看。
什?特殊字符,把字符串base64_encode後?出?看看。
[code=php]$str = '龙华
竟然不让贴php代码
$str = '龙华
什?特殊字符,把字符串base64_encode後?出?看看。
[code=php]$str = '龙华
我还是截图吧
请给出真实的数据
什?特殊字符,把字符串base64_encode後?出?看看。
请给出真实的数据
数据就是那些,我不知道还缺哪些数据? 特殊的字符我这里显示不出来。
header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpQ==';echo $t = base64_decode($s), PHP_EOL;echo bin2hex($t);龙华
header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpQ==';echo $t = base64_decode($s), PHP_EOL;echo bin2hex($t);龙华
header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';echo $t = base64_decode($s), PHP_EOL;echo pack("H*", bin2hex($t));
这样的就不行诶~~ 而且中间应该不是空格
你在做什么?
header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';$t = base64_decode($s), PHP_EOL;echo bin2hex($t);e9be99e58d8e f0afa0a5313233313233313233
不是跟你说了吗?那是表情符,PC 中的浏览器都是不会显示的
因为前端阻止不了用户的输入,需要后端过滤掉这些数据,然后才插入数据库的。
不然数据库里显示的信息不全。
把不是utf8的字符??就可以了。
header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';$t = base64_decode($s). PHP_EOL;echo $t.'<br>';echo filter_utf8_char($t);/** ??字符串,保留UTF8字母?字中文及部份符? * @param String $ostr * @return String */ function filter_utf8_char($ostr){ preg_match_all('/[\x{FF00}-\x{FFEF}|\x{0000}-\x{00ff}|\x{4e00}-\x{9fff}]+/u', $ostr, $matches); $str = join('', $matches[0]); if($str==''){ //含有特殊字符需要逐??理 $returnstr = ''; $i = 0; $str_length = strlen($ostr); while ($i<=$str_length){ $temp_str = substr($ostr, $i, 1); $ascnum = Ord($temp_str); if ($ascnum>=224){ $returnstr = $returnstr.substr($ostr, $i, 3); $i = $i + 3; }elseif ($ascnum>=192){ $returnstr = $returnstr.substr($ostr, $i, 2); $i = $i + 2; }elseif ($ascnum>=65 && $ascnum<=90){ $returnstr = $returnstr.substr($ostr, $i, 1); $i = $i + 1; }elseif ($ascnum>=128 && $ascnum<=191){ // 特殊字符 $i = $i + 1; }else{ $returnstr = $returnstr.substr($ostr, $i, 1); $i = $i + 1; } } $str = $returnstr; preg_match_all('/[\x{FF00}-\x{FFEF}|\x{0000}-\x{00ff}|\x{4e00}-\x{9fff}]+/u', $str, $matches); $str = join('', $matches[0]); } return $str; }
龙华
不是前台输入什么,数据库就要存什么的,输入要做一下限制,然后再存。可以跟上级沟通一下。

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

The session ID should be regenerated regularly at login, before sensitive operations, and every 30 minutes. 1. Regenerate the session ID when logging in to prevent session fixed attacks. 2. Regenerate before sensitive operations to improve safety. 3. Regular regeneration reduces long-term utilization risks, but the user experience needs to be weighed.

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!