Jump to content

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*

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.