PHP 项目从 IIS 转移到 Apache 服务器时出现错误

发布于 2024-12-17 02:18:17 字数 734 浏览 2 评论 0原文

我在IIS上的WebMatrix中开发了一个php项目。在这个项目中,我不小心两次缩写了相同的“会话变量”。

     Example: File - a.php

     <?php
     $_Session['one'];
     include 'b.php';
     ...........
     ...........
     ...........
     ...........
     ?>

     Example: File - b.php

     <?php
     $_Session['one'];
     ...........
     ...........
     ...........
     ...........
     ?>

当我从 Webmatrix(IIS 服务器)运行此项目时,未显示此错误,但当我在 Apache 上运行此项目时,显示了此错误,我纠正了我的缺陷。

   Warning on Apache:
   Notice: A session had already been started - ignoring session_start() in D:/path/.

我的问题是为什么这个错误没有提前显示?是否与 IIS 服务器或 WebMatrix 有关。我总是需要注意代码中的错误或警告,以便我可以消除它们并保持代码的效率,请建议我一些理想的 php 开发工具,它可以捕获代码中的小错误。

I developed a php project in WebMatrix on IIS. In this project I accidently initialed same "session variable" twice.

     Example: File - a.php

     <?php
     $_Session['one'];
     include 'b.php';
     ...........
     ...........
     ...........
     ...........
     ?>

     Example: File - b.php

     <?php
     $_Session['one'];
     ...........
     ...........
     ...........
     ...........
     ?>

When I run this project from Webmatrix(IIS server) this error wasn't shown but when I ran this project on Apache this error was displayed and I corrected my flaws.

   Warning on Apache:
   Notice: A session had already been started - ignoring session_start() in D:/path/.

My question is that why this error was not shown earlier? Is it something related to IIS server or WebMatrix. I always need to be aware of the errors or warnings in the code so that I can get rid of them and the efficiency of the code is sustained, please do suggest me some ideal php develeopment tools which can catch even minor errors in my code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蘑菇王子 2024-12-24 02:18:17

确保显示错误,然后尝试在应用程序开始时将 error_reporting 一直调高。

ini_set('display_errors', 1);
error_reporting(E_ALL);

另外,请注意 Windows 区分大小写。你可以说 include 'A.php'include 'a.php' 它不会关心。但是,当您将其放在区分大小写的基于 Linux 的服务器上时,它可能无法找到文件 A.php(如果它实际上是 a.php) >。

Ensure errors are being displayed and then try turning error_reporting all the way up at the beginning of the application.

ini_set('display_errors', 1);
error_reporting(E_ALL);

Also, be aware that Windows is not case-sensitive. You could say include 'A.php' or include 'a.php' and it would not care. However, when you put it on a Linux-based server, which is case-sensitive, it may not be able to find the file A.php if its actually a.php.

等风来 2024-12-24 02:18:17

您可能会遇到错误,因为第一台服务器运行的是 PHP 4,第二台服务器运行的是 PHP 5。双重包含包含函数的文件将在这些版本中获得不同的结果。请参阅此链接中示例 6 之前的文本: http://php.net/manual/ en/function.include.php

编辑:我相信您编辑的帖子中生成的错误消息表明了不同性质的内容。

对于您想要确保只包含一次的文件,请使用 include_once()http://www.php.net/manual/en/function.include -once.php

在某些情况下,您可能合法地希望从文件中 include() 两次。但由于这些情况很少见,因此最好使用 include_once()

It's possible you got errors because the first server was running PHP 4 and the second is PHP 5. Double-including a file containing functions will get different results in those versions. See the text just before example 6 in this link: http://php.net/manual/en/function.include.php

EDIT: I believe the error messages generated in your edited post indicate something of a different nature.

For files that you want to make sure they are only included one time, use include_once(). http://www.php.net/manual/en/function.include-once.php

There are some situations where you may legitimately want to include() twice from a file. But because those situations are rare, it's best to use include_once().

心在旅行 2024-12-24 02:18:17
Warning on Apache:
   Notice: A session had already been started - ignoring session_start() in D:/path/.

您无法再次启动已经启动的会话。

当您包含 b.php 时,您需要在 a.php 处启动 1 个会话,它可以使用已启动的会话。

它是一个警告,警告意味着它不好,但 php 可以修复此错误并继续工作。

这一切都与错误报告级别有关。

Warning on Apache:
   Notice: A session had already been started - ignoring session_start() in D:/path/.

You can't start session again which is already started.

You need 1 session start at a.php when you include b.php it can use started session.

Its a warning and warning means its not good but php can fix this error and continue working.

Its all about error reporting level.

少钕鈤記 2024-12-24 02:18:17

很难判断该错误是否不是发生在 IIS 上。仅因为它没有显示或记录,并不意味着它没有发生。请比较两个系统之间的错误报告 php.ini 配置。

您应该在配置中比较的另一件事是 if session auto -start 是否已在旧系统或新系统上启用。这可能会触发您的错误,但这只是猜测。正如所写,该错误可能已经存在于旧系统上,但只是未被注意到。

It is hard to tell if the error didn't occured on IIS or not. Only because it was not displayed or logged, does not mean it didn't occur. Please compare the error reporting php.ini configuration between both systems.

Another thing you should compare in configuration is if session auto-start had been enabled on the old or new system or not. This might be triggering your error, but it's only a guess. As written the error might have been already on the old system but just was unnoticed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文