我一直在学习 php,只是埋头苦干。
我希望有人能在安全、流程和一般最佳实践方面为我指明正确的方向?
谢谢。
编辑--
我想一个更好的方式来表达我想问的是..
什么是最佳实践:
1.) 当用 php 处理表单时,get vs post,$_REQUEST vs $_GET & $_POST
2.) 动态创建 HTML 文件时(下面的示例)
3.) 在与表单创建者相同的文件中登录和验证
4.) 用 php 发送电子邮件
来自上面#2
<?php
echo "<h1> Welcome </h1>";
if ($_SESSION['type'] == "admin")
{
//lots of html in the echo statment
echo "tables and admin interface here";
} else
{
//lots of html in the echo statment
echo "tables and user dashboard here";
}
?>
--VS--
<h1> Welcome </h1>
<?php
if ($_SESSION['type'] == "admin")
{
?>
lots of html in the echo statment
tables and admin interface here
<?php
} else
{
?>
lots of html in the echo statment
ables and user dashboard here
<?php
}
?>
--VS--
<?php if($_SESSION['username']): ?>
<p>You are logged in as <?=$_SESSION['username']?></p>
<p><a href="?logout=1">Logout</a></p>
<?php endif; ?>
附言: 感谢所有已经回复的人。 我还可以查询框架适合哪里吗?我上了一门 OOP 类(class),但我们并不熟悉任何框架。
我阅读了很多有关 Symfony 和 zend 框架的资料,但仍然感到困惑。
再次感谢。
最佳答案
好的编程与语言无关。我建议你开始学习软件开发概念,例如面向对象编程、设计模式、关注点分离、重用、封装、测试和重构。从其中任何一个开始,并在 list 上“坚持”下去,你会变得更好。
特定于 PHP - 学习公认的编码标准,例如 PEAR的或 Zend的。吸收了一些概念后,选择一个很好的引用,例如其他答案中提到的顶级框架之一 - Zend Framework、CakePHP、Symfony 等。
关于php - 是否有 "right"方式来使用 php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3983273/