Jump to content

Need help with Constants


doubledee

Recommended Posts

I would like to define two constants to switch where my "Web Root" is located so I can go between my laptop and web host.

 

I created a "config.inc.php"

 

<?php
// Constants for Web Roots.
define('DEV_ROOT', '/00_MyWebsite/');
define('PROD_ROOT', 'w w w.MyWebsite.com/');
?>

 

and then in my "checkout.php" page I have...

 

<body>
<!-- Access Web Root Constants -->
<?php	require_once "../config.inc.php";
			echo 'DEV _ROOT = ' . DEV_ROOT;
			echo 'PROD _ROOT = ' . PROD_ROOT;
?>

 

But that doesn't seem to work so far.

 

I know what I'm trying to do, but am getting stuck on how to do it?!  :confused:

 

Can someone help straighten me out??

 

Thanks,

 

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/234462-need-help-with-constants/
Share on other sites

What do you mean by " that doesn't seem to work so far." What is happening or not happening?

 

Ken

 

I switched where my echo was at and it seems like my constants are at least printing now.  (Strange behavior!!  I think since all of my links and includes are toast things are acting strangely?!)

 

I got this...

 

DEV_ROOT = localhost/00_MyWebsite/

PROD_ROOT = www.MyWebsite.com/

 

 

So, anyhow, here is a slightly larger code snippet...

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<!-- Include HTML Metadata -->
<?php	require_once "../components/html_meta.inc.php";	?>

<!-- Page Stylesheets -->
<link type="text/css" rel="stylesheet" href="../css/pagelayout_3col3.css" />
<link type="text/css" rel="stylesheet" href="../css/dropdown04.css" />
<link type="text/css" rel="stylesheet" href="../css/footer-.css" />
</head>

<body>
<!-- Access Web Root Constants -->
<?php	require_once "../config.inc.php";	?>


<div id="wrapper" class="clearfix">
	<div id="inner">
		<!-- Include BODY HEADER -->
			<?php	//require_once "../components/body_header.inc.php";	?>

 

How can I hook up the above file paths to a Constant so that I get the desired effect when I'm on my laptop or web host, respectively?

 

 

 

Debbie

 

 

I'm really struggling with file paths today...  :'(

 

Here is my local directory structure...

 

00_MyWebsite
Source Files
	components
		body_header.inc.php
		body_footer.inc.php

	secure
		checkout.php

	images
		my_logo.png

	index.php
	product_details.php

 

When I am in "checkout.php" and use this code...

 

<?php	require_once('../components/body_header.inc.php');	?>

 

...my Header appears.

 

But when I try to require the header file using my new DEV_ROOT constant, I can't figure out what the constant and path should be to get it working?!  :'(  :'(

 

Can someone help me understand what to do?

 

Thanks,

 

 

 

Debbie

 

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.