Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
htmlspecialchars($服务器[";PHP\u SELF";]),在字符串中添加变量_Php_Htmlspecialchars - Fatal编程技术网

htmlspecialchars($服务器[";PHP\u SELF";]),在字符串中添加变量

htmlspecialchars($服务器[";PHP\u SELF";]),在字符串中添加变量,php,htmlspecialchars,Php,Htmlspecialchars,我试图插入PHP来构建动态内容,但我在表单方面遇到了一些问题: $content_message = "<p class='notification'>Please type in and confirm your new password.</p>" . '<form method="post" id="change_password" action="htmlspecialchars(' . $_SERVER["PHP_SELF"] . '?id=' .

我试图插入PHP来构建动态内容,但我在表单方面遇到了一些问题:

$content_message = "<p class='notification'>Please type in and confirm your new password.</p>"
    . '<form method="post" id="change_password" action="htmlspecialchars(' . $_SERVER["PHP_SELF"] . '?id=' . $id . '&code=' . $code . ')">'
$content\u message=“

请键入并确认您的新密码。

” . ''

我找不到一种方法使
htmlspecialchars
$\u服务器[“PHP\u SELF”]
以及字符串中添加的变量一起工作


任何帮助都将不胜感激

不要消毒
htmlspecialchars
。这样做:

$content_message = "<p class='notification'>Please type in and confirm your new password.</p>"
               . '<form method="post" id="change_password" action="'.htmlspecialchars(
               . $_SERVER["PHP_SELF"]
               . '?id='
               . $id
               . '&code='
               . $code
               . ).'">'
$content\u message=“

请键入并确认您的新密码。

” . ''

还请记住,浏览器将表单发送到当前打开的相同地址,因此无需调用
action=PHP\u SELF
。您可以省略操作属性。

如果要发送动态值,则可以轻松地使用输入隐藏标记放置,信息也将是安全的

就这样,

$content_message = "<p class='notification'>Please type in and confirm your new password.</p>"
               . '<form method="post" id="change_password" action="" >
               <input type="hidden" name="id" value="'.$id.'" />
               <input type="hidden" name="code" value="'.$code.'" />
               <form/>';

希望,这可能会对您有所帮助。

htmlspecialchars(
is PHP)将其从字符串中去掉。例如
action=“””。htmlspecialchars(
encode
$id
$code
分别编码,否则
&code=
将成为
id
的一部分,就像
$code
一样。@sebjel您想要执行的任何代码都必须从字符串中取出。使用适当的IDE(类似于PHPStorm),它将帮助您创建更清晰的代码。您还应该尝试将您的逻辑与HTML分离。查看MVC(模型、控制器、视图)和创建HTML模板(可能查看Twig或Blade HTML模板)。这将有助于您创建更干净、更易管理和更少错误的代码。这些是我希望人们在我刚开始时告诉我要研究的事情,从长远来看,这将对您有很大帮助。此外,还要研究微服务(在您了解其他内容之后)@sebjel您可能还想简单地将
action='page.php'
(很明显,无论您真正想要访问哪个页面),然后通过PHP会话发送参数,这样就不能通过代码检查轻松地操作这些值,而且还可以防止出现难看的URL
echo $_POST['id'];
echo $_POST['code'];