search
HomeBackend DevelopmentPHP Tutorial 运用和学习PHP有多难

使用和学习PHP有多难

PHP不是什么复杂高深的技术,但同时,你也不要期望能够在5分钟之内就成为专家。对于新手来说,最大的不适应可能就是PHP的容错度比浏览器对HTML的容错度要低得多。在HTML中如果漏掉了一个结束标签,大多数的浏览器仍然会显示该页面。在PHP中,如果你漏掉了一个结束引号、分号或大括号,将会像图1-3所显示的那样得到一条错误消息。这不仅仅是PHP的一个特性,所有的服务器端技术都是如此,包括ASPASP.NETColdFusion

?

1-3 像PHP这样的服务器端语言无法容忍大多数的编码错误

如果你是使用可视化设计工具(如Adobe DreamweaverMicrosoft Expression Web)的网页设计人员或开发人员,并且从不留意基础代码,那么是时候该反思一下你的方法了。将PHP和结构差的HTML混合在一起有可能会导致一些问题。PHP利用循环来执行重复性任务,如显示数据库搜索的结果。一个循环loop)重复同一段代码(代码通常同时包含PHPHTML),直至所有的结果都显示出来。如果你将循环放到了错误的位置,或者HTML的结构差,那么页面就有可能像用纸牌搭的房子一样倒塌。如果你还不习惯这样做,使用W3CWorld Wide Web ConsortiumMarkup Validation Servicehttp://validator.w3.org/unicorn)来检查你的页面是一个不错的主意。

W3C是一个国际组织,它负责制定标准(如HTMLCSS),并制定保证Web长期发展的指导方针。它由World Wide Web的创立者Tim Berners-Lee所领导。要想了解W3C的使命,参见www.org/Consortium/mission

?? 是否可以只复制和粘贴代码

?

复制这本书中的代码没什么错,这正是它们存在的目的。复制是我们小时候都学习过的方法,但我们大多数人都会摆脱模仿的阶段,我们会提出问题并且开始亲自实验。我并不打算用一些对于网页没有直接价值的乏味的练习题来教你学习PHP,本书就是要让你可以直接将新获得的知识运用到实际项目中。同时,我会解释代码是用来做什么的以及它为什么出现在那里。即使不能准确地理解它的工作原理,你也会获得足够的知识来了解代码的哪个部分适合你的需要,哪个部分最好不要去理会。

PHP是一个提供了大量强大功能的工具箱。它拥有数千个内置函数,可以执行各种任务,如将文本转换成大写,从完整尺寸的图像生成缩略图,或连接到数据库。真正的强大之处在于将这些函数以不同的方式组合使用,并且添加进你自己的条件逻辑。为了从本书中学到更多内容,你需要用你在书中学到的工具进行实验,并且提出你自己的解决方案。

PHP的安全性

PHP就像是你家中的电或菜刀:如果正确使用,它是非常安全的;如果不负责任地操作,它就会造成许多伤害。本书第1版的灵感之一就来自2005年年末接二连三爆发的恶意攻击。这些攻击利用了电子邮件脚本的一个漏洞,将网站变成了垃圾邮件中继。没有几个人免遭危害。我当然也未能幸免,但是意识到这个问题以后,我修补了漏洞,并及时制止了这些恶意攻击。不过,每天都有人发送紧急的请求到在线论坛上以寻求帮助。即使被告知如何处理这种问题时,他们的回复甚至变得更加抓狂。许多人承认他们完全不了解他们在网站中使用的代码。有些人把创建网站当成一种业余爱好,这似乎是可以理解的,但是这些人中有许多都是替客户创建网站的“专业人士”。当这些客户们的邮箱开始充满垃圾邮件时,他们自然就会很不高兴。当主机托管公司由于无法忍受服务器上的不安全脚本而将客户的域名禁用时,他们毫无疑问会更加不高兴。

这个故事的寓意不在于PHP是不安全的;也不在于每个人都需要成为使用PHP的安全专家。重要的是了解PHP安全性的基本原则:在处理用户输入之前必须进行检查你会发现这将成为贯穿本书始终的主题。只要付出很少的努力,大多数的安全风险就能够被消除。

最令人担心的方面可能是在这个问题被首次揭示出来五年多之后,我仍然能看到许多人在使用不安全的邮件脚本。保护自己的最佳方法就是了解你正在使用的代码。即使你不能自己解决问题,也可以实施由脚本的编写者或其他专家建议的补救措施。?

――摘自《PHP动态网页设计(第2版)》

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment