美元($)登录密码字符串被视为变量 [英] Dollar ($) sign in password string treated as variable

查看:83
本文介绍了美元($)登录密码字符串被视为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

花费一些时间来解决PHP / MySQL Web应用程序连接到数据库时出现问题的问题。可以从shell和phpMyAdmin访问数据库,具有完全相同的凭据,这没有任何意义。

Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems connecting to the database. The database could be accessed from the shell and phpMyAdmin with the exact same credentials and it didn't make sense.

结果出现了一个$ sign的密码: / p>

Turns out the password had a $ sign in it:

$_DB["password"] = "mypas$word";

正在发送的密码是mypas,显然是错误的。

The password being sent was "mypas" which is obviously wrong.

处理这个问题的最好方法是什么?我逃避了$ \\ $

What's the best way to handle this problem? I escaped the $ with a \

$_DB["password"] = "mypas\$word";

它的工作。

使用 $ string ='test'的字符串,这可能是我以前避免了进入这个。

I generally use $string = 'test' for strings which is probably how I avoided running into this before.

这是正确的行为吗?如果这个密码存储在数据库中,并且PHP将其删除,那会怎么样呢?我在这里缺少什么...

Is this correct behavior? What if this password was stored in a database and PHP pulled it out - would this same problem occur? What am I missing here...

推荐答案

$_DB['password'] = 'mypas$word';

单引号字符串不会按原样处理。您应该始终使用单引号字符串,除非您特别需要$变量或转义序列(\\\
,\r等)替换。它更快,更不容易出错。

Single quote strings are not processed and are taken "as-is". You should always use single quote strings unless you specifically need the $variable or escape sequences (\n, \r, etc) substitutions. It's faster and less error prone.

这篇关于美元($)登录密码字符串被视为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆