初学者PHP类的在线代码编辑器 [英] Online code editor for beginner's PHP class

查看:60
本文介绍了初学者PHP类的在线代码编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设你想用Moodle教一个PHP的入门课程

编程。有些学生很少或没有计算机经验。


除了背景阅读和面向主题的作业

由Moodle提供,你想建立一个在线文本编辑器进入了

课程,因此学生可以直接在服务器上输入他们的PHP程序和HTML到

文件,这样他们就不必与NotePad打架在Windows上

实验室中的个人计算机,所以初学者不必与FTP战斗,以获得
将他们的工作带到网络服务器上。


你可以制作一个表格:(没有错误检查等以简化)

$ path =

$ _GET [''dirpath'']。 ''/ myassignment'';

echo''< form action ="''。$ _ SERVER [''PHP_SELF'']。''" method =" post">< br>

< textarea name =" editor">''。@ file_get_contents($ path)。''< / textarea>

< input type =" submit">< / form>'';


if($ _ SERVER [''REQUEST_METHOD''] == ''POST'')

{

$ fp = fopen($ path," w");

fwrite($ fp, $ _POST [''编辑'']);

fclose($ fp);

}


大多数开发者喜欢使用addslashes或htmlentities清理用户输入
POST处理中的
。但如果您在在线代码编辑器中执行此操作,那么您将获得不会运行或显示的代码。所以,如果你没有这么多,那么你仍然想覆盖你的基地,有什么问题呢?


学生必须登录(密码)访问编辑器。所以

这个编辑器不适用于全世界。但是相信

密文学生仍然可能不是一个好主意。 fopen必须是限于特定位置模式的b $ b。也许你必须使用

正则表达式来查找javascript,然后将其删除。

但是如果你想教javascript怎么办?在线编辑器

比让学生通过FTP上传代码更危险吗?

解决方案

path =

_GET [ '' dirpath '']。 ''/ myassignment'';

echo''< form action ="''。


_SERVER [''PHP_SELF'']。'' " method =" post">< br>

< textarea name =" editor">''。@ file_get_contents(


Let''s say you want to use Moodle to teach an introductory class in PHP
programming. Some of the students have little or no computer experience.

In addition to background reading and topics-oriented assignments
supplied by Moodle, you want to build an online text editor into the
course, so students can type their PHP programs and HTML directly into
files on the server, so they don''t have to fight with NotePad on Windows
PCs in a lab, and so beginning students don''t have to fight with FTP to
get their work onto the webserver.

You could make a form: (no error checking etc. for simplicity)
$path =
$_GET[''dirpath'']. ''/myassignment'';
echo ''<form action="''.$_SERVER[''PHP_SELF''].''" method="post"><br>
<textarea name="editor">''.@file_get_contents($path).''</textarea>
<input type="submit"></form>'';

if($_SERVER[''REQUEST_METHOD''] == ''POST'')
{
$fp = fopen($path,"w");
fwrite($fp,$_POST[''editor'']);
fclose($fp);
}

Most developers like to clean user input with addslashes or htmlentities
in the POST processing. But if you do that in the "online code editor"
case you get code that won''t run or display. So, if you do not
addslashes, but you still want to cover your bases, what are the issues?

Students would have to login (password) to get access to the editor. So
this editor is not available to the world at large. But trusting
passworded students still may not be a good idea. fopen would have to be
limited to specific location patterns. Perhaps you would have to use
regular expressions to look for javascript, and then to strip it out.
But what do you do if you want to teach javascript? Is an online editor
any more dangerous than letting students upload code via FTP?

解决方案

path =


_GET[''dirpath'']. ''/myassignment'';
echo ''<form action="''.


_SERVER[''PHP_SELF''].''" method="post"><br>
<textarea name="editor">''.@file_get_contents(


这篇关于初学者PHP类的在线代码编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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