search
HomeBackend DevelopmentPHP Tutorial 说一个很多菜鸟(例如小弟我)都遇到的有关问题的解决办法,当然这个解决办法却引出另一个有关问题,求解!

说一个很多初学者(例如我)都遇到的问题的解决方法,当然这个解决方法却引出另一个问题,求解!!
大家(超级初学者们),是不是都试过php不能解析,也就是用浏览器打开的php文件,里面的html内容可以正常解析显示出来,但是php的代码却只能当成是源代码显示出来,即使你已经经过了常人所不能忍受的调试以及apache的连夜配置,也都失败,那就在你即将放弃的时候,我(刚刚连夜弄个一共20个小时还是失败的超级小白),告诉你吧(刚刚和我一起奋战研究的同学终于搞出来了),其实:我们需要把我们的php放在apache的默认目录(比如我的linux就是/var/www/html里面)下,就能被正常解析,赶紧试试吧!!


PS:因为我是刚刚知道太过激动才忍不住上来分享了的,没有去看论坛有没有相同的解决方法,也没有看有没有人遇到这个问题(如果没有人遇到这个弱智问题,我就尴尬了…………),所以不知到的同学尽管拿去,知道的高手们也不要笑我,呵呵



另外,问题来了,据我所知,好像只有我,和我的同学必须得 “ 把我们的php放在apache的默认目录 ”才能解析,网上其他人都是不需要的,所以说其实我这个所谓的解决方法只是另外一个没有那么严重的问题而已~~~所以在这求助大家,怎么办啊~~我想在电脑的其它地方也能进行php编程啊……………………~~~~!!!!

------解决方案--------------------
去网上搜“配置apache虚拟主机”看看。
------解决方案--------------------
印象里好像有1/500的机会出现你说的事情.

如果出现显示源码的话基本上可以肯定是apache 没有给他解析这个后缀.php的配置信息
如果出现下载文件的话基本上可以肯定的是php没有正常的安装.

如果出现只能在默认目录才能看到文件的话,那你的apache配置应该没有正确的设置根目录位置...

挺多的.不过其实也就那么点事.如果你只是初学为了php 暂时不要在这里纠结,先下个xampp安装了去吧.
有很多公司你去的时候这些都是已经完善了的,你只需要了解目录结构,会ftp就完事了.后期的话你可以自己去学一学
还有vcs.
------解决方案--------------------
输出phpinfo 看看你的phpinfo是否能够正常的解析.如果可以的话那么就要考虑你是不是写了短标签.
如果不行那就还是要回去调试apache.

探讨

引用:

印象里好像有1/500的机会出现你说的事情.

如果出现显示源码的话基本上可以肯定是apache 没有给他解析这个后缀.php的配置信息
如果出现下载文件的话基本上可以肯定的是php没有正常的安装.

如果出现只能在默认目录才能看到文件的话,那你的apache配置应该没有正确的设置根目录位置...

挺多的.不过其实也就那么点事.如果你只是初学为了p……

------解决方案--------------------
必须要以“主机名”来访问才能被apache解析。localhost 就代表本机。
------解决方案--------------------
我前几天也遇到同样的情况,lz说的是一种,但是要是单单浏览页面的话,也可以把.php文件改成.html的,可以放到电脑的其它位置正常浏览,不会只显示源代码
------解决方案--------------------
你重心放错地方了,你的重心应该是如何运用PHP,而不是配置PHP环境,就像你用电脑,但不一定需要知道电脑的运行机制的。配置运行环境你只需要大概了解就行,不需要太深入。以后弄PHP,直接用集成安装包弄就行了。
------解决方案--------------------
这应该是个常识吧,不放在解析目录里,当然不会被解析,当然,这个目录不一定是固定的,也可以设置的
------解决方案--------------------
探讨

引用:

你重心放错地方了,你的重心应该是如何运用PHP,而不是配置PHP环境,就像你用电脑,但不一定需要知道电脑的运行机制的。配置运行环境你只需要大概了解就行,不需要太深入。以后弄PHP,直接用集成安装包弄就行了。


我现在也有这种感觉,干脆我就在localhost练习算了,不追求方便了,反正到时搭载服务器之后外界是一定会通过web服务器进行解析php的,应该不……
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
How does PHP identify a user's session?How does PHP identify a user's session?May 01, 2025 am 12:23 AM

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

What are some best practices for securing PHP sessions?What are some best practices for securing PHP sessions?May 01, 2025 am 12:22 AM

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

Where are PHP session files stored by default?Where are PHP session files stored by default?May 01, 2025 am 12:15 AM

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

How do you retrieve data from a PHP session?How do you retrieve data from a PHP session?May 01, 2025 am 12:11 AM

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

How can you use sessions to implement a shopping cart?How can you use sessions to implement a shopping cart?May 01, 2025 am 12:10 AM

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

How do you create and use an interface in PHP?How do you create and use an interface in PHP?Apr 30, 2025 pm 03:40 PM

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

What is the difference between crypt() and password_hash()?What is the difference between crypt() and password_hash()?Apr 30, 2025 pm 03:39 PM

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

How can you prevent Cross-Site Scripting (XSS) in PHP?How can you prevent Cross-Site Scripting (XSS) in PHP?Apr 30, 2025 pm 03:38 PM

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

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.