Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Php 使文本输入只包含字符串而不包含代码_Php_Html_Css - Fatal编程技术网

Php 使文本输入只包含字符串而不包含代码

Php 使文本输入只包含字符串而不包含代码,php,html,css,Php,Html,Css,我有个问题 我正在用php进行实时聊天(我是php新手),它以您的名字,$theName和theMessage,然后将其写入txt文件,然后读取txt文件并显示在index.php上。我的问题是,在消息框中,您可以编写类似于Hello的内容,这样会使消息变为绿色。你是如何做到用户不能在输入中输入代码,而只是一个简单的字符串 以下是我的php的一部分: $handle = fopen("view.txt", "a"); fwrite($handle, $theName . " - " . $the

我有个问题

我正在用php进行实时聊天(我是php新手),它以您的名字,
$theName
theMessage
,然后将其写入txt文件,然后读取txt文件并显示在index.php上。我的问题是,在消息框中,您可以编写类似于
Hello
的内容,这样会使消息变为绿色。你是如何做到用户不能在输入中输入代码,而只是一个简单的字符串

以下是我的php的一部分:

$handle = fopen("view.txt", "a");
fwrite($handle, $theName . " - " . $theMessage . "\n"); //this is where you can put code that I don't want
fclose($handle);
$theName = NULL;
$theMessage = NULL;
echo $emptyLink;  //the index.php
你有所见即所得的插件,使它正确(例如:TinyMCE)。 把它包含在你的聊天系统中,它会为你带来好处


但如果您坚持,
htmlspecialchars()
将允许您拥有一个不能作为HTML而作为字符串读取的字符串。然后您可以在处理过程中使用它。

这称为XSS漏洞。而且它是通过使用来防止的。好的。那么,我该如何向我的代码暗示这一点呢?蓝色文本是一个可以点击的链接。这很有帮助。我现在正在用我的php开发它!