简体   繁体   English

PHP常量有时不被其定义的值替换

[英]PHP constant is sometimes not replaced by its defined value

I'm quite confused by this problem I'm having as the code produces intermittent results. 我对代码产生间歇性的结果感到困惑。

I have a PHP application developed in CodeIgniter, a part of the software sends review emails with a link in. The link is declared like this in the code and this link is used to build the HTML email body: 我有一个用CodeIgniter开发的PHP应用程序,该软件的一部分发送带有链接的审阅电子邮件。该链接在代码中声明如下,该链接用于构建HTML电子邮件正文:

$link = BASE_URL.'/review?id='.$review_id;

BASE_URL is a constant defined like so: BASE_URL是如下定义的常量:

define('BASE_URL', 'http://www.domain-name.com');

Most of the time the link in the email is well formed and the constant is replaced with the domain name. 大多数情况下,电子邮件中的链接格式正确,并且用域名替换常量。 However we've had replies to the review email where the user says the link does not work for them. 但是,我们已经收到了对审阅电子邮件的答复,其中用户说该链接不适用于他们。 Then looking at the link in the email to which they replied to, the link then has this url: 然后查看他们回复的电子邮件中的链接,然后该链接具有以下URL:

base_url/review?id=1234

Now this seems like very strange behaviour as the code produces 2 different results. 现在这看起来很奇怪,因为代码会产生2个不同的结果。 What could be the cause of such an issue? 造成此问题的原因可能是什么? Has any experienced something like this before? 以前有没有经历过这样的事情?

I'd suggest you first use the framework itself for base_url(); 我建议您首先将框架本身用于base_url();

other than that, if you can't track it down, I suggest logging the link you send to a file and see what value it gets when that link it sent. 除此之外,如果您无法对其进行跟踪,建议您将发送的链接记录到文件中,并查看发送该链接时获得的值。

Where is the definition taking place? 定义在哪里发生? this indeed sounds like what lupatus wrote, so maybe you call it before you define it. 这确实听起来像lupatus编写的内容,所以也许您在定义它之前先调用它。

We're pretty much guessing as this is 101 debugging :) 我们正在猜测,因为这是101次调试:)

<?php echo base_url();?>

将以上代码替换为BASE_URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM