Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Defined path not being parsed

Posted on 2006-05-05
11
Medium Priority
?
187 Views
Last Modified: 2006-11-18
I have two files...

index.php
----------------------------------------------------------
<?php
### paths - i.e define('INCLUDES_DIR', ROOT . 'includes/'); ###
include("includes/config/paths.php");
?>

SOME HTML...


### INCLUDE 1 ###
<?php include("includes/nav.inc.php"); ?>

### INCLUDE 2 ###
<?php include(INCLUDES_DIR . "nav.inc.php"); ?>


SOME HTML...
----------------------------------------------------------


nav.inc.php
----------------------------------------------------------
<img src="<?php echo IMAGES_DIR . "users-icon.gif" ?>" />
----------------------------------------------------------


With "INCLUDE 1" the image will show (with the absolute path to the image) but with "INCLUDE 2" the defined images directory will not parse and will output like so:

<img src="IMAGES_DIRusers-icon.gif" />


(1). Why is "IMAGES_DIR" not being parsed and (2). how can I solve the problem? I guess I could just use "INCLUDE 1" instead but is there another way?.

(3). What would be the best way to layout the structure of the site? (could you point me towards some links, articles etc.)


Thanks.
0
Comment
Question by:arse_soul
  • 4
  • 4
  • 3
11 Comments
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16614084
First of all, you have asked 3 questions under one. This is against the experts-exchange system, I believe.
Second question is related to first, so it's no big deal. However, you should ask the last one in a different area than PHP and as a separate question.

I will answer the first question for you here.

I assume IMAGES_DIR is a variable and therefore should be written as $IMAGES_DIR (it's case-sensitive, so be sure it's all uppercase variable).

So: <img src="<?php echo $IMAGES_DIR . "users-icon.gif"; ?>" />

Comments: you might want to use print statement instead of echo, as echo won't work this way in all cases. See http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 for more detailed information.

regards,
CyberGhost
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16614090
update: you might want to change "INCLUDES_DIR" to "$INCLUDES_DIR" in that INCLUDE #2
0
 

Author Comment

by:arse_soul
ID: 16614550
IMAGES_DIR is a constant and so is INCLUDES_DIR.

define('INCLUDES_DIR', ROOT . 'images/');
define('INCLUDES_DIR', ROOT . 'includes/');

so $ to denote a variable is not required

define("GREETING", "Hello you.", true);
echo GREETING; // outputs "Hello you."
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:CyberGhost
ID: 16615101
Sorry, I've apparently missed that one out.
Then check if that constant is defined and if so, if its value is correct.
I can't see anything wrong in that code.

regards,
CyberGhost
0
 

Author Comment

by:arse_soul
ID: 16615417
yup the constant is defined and the value is correct.

thanks for trying!
0
 
LVL 5

Expert Comment

by:funamentalist
ID: 16624553
Hi

you might try checking the constants value before the include

<?php
### paths - i.e define('INCLUDES_DIR', ROOT . 'includes/'); ###
include("includes/config/paths.php");
?>
<?php
echo INCLUDES_DIR;
include(INCLUDES_DIR . "nav.inc.php");
?>

if that echo prints something then the chances are that the constant is being overwritten/redeclared somewhere in the nav.inc.php file.

let me know how that goes.
0
 

Author Comment

by:arse_soul
ID: 16629379
The echo does output correctly.

http://localhost/site/includes/

If you recreate the problem I outlined above (adding no extra lines of code) and assuming the defines are correct and in place for the root dir, the includes dir and the images dir the image does not show when "INCLUDE 2" is used.
0
 
LVL 5

Expert Comment

by:funamentalist
ID: 16629612

can u post relevant code here from the include ? that will probably help alot.
0
 
LVL 5

Accepted Solution

by:
funamentalist earned 1000 total points
ID: 16629618
sorry .. i figured this out..


the thing is includes dont work with web paths like http://localhost/site/includes/

they will work with /home/acccount/httpdocs/includes etc.

so u need a different constant than the webpath
ROOT should be the physical path of the site.
0
 

Author Comment

by:arse_soul
ID: 16632212
thanks!
0
 
LVL 5

Expert Comment

by:funamentalist
ID: 16632276
glad could be of help , thanks for the points :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question