简体   繁体   中英

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:

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

BASE_URL is a constant defined like so:

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:

base_url/review?id=1234

Now this seems like very strange behaviour as the code produces 2 different results. 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();

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.

We're pretty much guessing as this is 101 debugging :)

<?php echo base_url();?>

将以上代码替换为BASE_URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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