Jump to content

Can't use Constant on required page


Jessica

Recommended Posts

I have a page like this:

define("ADMIN_URL", "admin/");
require_once(ADMIN_URL.'admin_menu.php');

 

And this works fine, the admin_menu.php is included. But in admin_menu.php I have:

<li><a href="<?=ADMIN_URL?>categories/">Categories</a></li>

And it prints out

<li><a href="ADMIN_URLcategories/">Categories</a></li>

 

I'm able to use the other constants I've defined on other included pages...what am I missing here?

Link to comment
https://forums.phpfreaks.com/topic/36513-cant-use-constant-on-required-page/
Share on other sites

Hmmm... that works for me.  Are you sure that you're viewing admin_menu.php from the context of the php page where ADMIN_URL is defined? 

 

index.php:

<?php
define("ADMIN_URL", "foo/");
require_once(ADMIN_URL.'foo.php');
?>

 

foo/foo.php

<?=ADMIN_URL?>

 

From index.php output = foo/

From foo/foo.php output = ADMIN_URL

 

Best,

 

Patrick

Here's a better explanation:

index.php:

define("ADMIN_URL", 'http://site.com/admin/');
print ADMIN_URL; //This works.
require_once('header.php');

 

header.php:

print ADMIN_URL; //This works.
require_once('admin_menu.php');

 

admin_menu.php:

print ADMIN_URL; //This does not work

 

PS: It's PHP 5, not 4, if it matters?

 

Edit: and finally, it appears admin_menu.php cannot see any of the variables or constants defined on index.php. :( This is very confusing, as I have done similar on other pages and it works fine. *grr*

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.