Jump to content

[SOLVED] What would the correct path be so my files can be found on the server?


trixiesirisheyes

Recommended Posts

I'm pretty sure the issue is a path problem and I'm not sure how to resolve it. I think Dreamweaver is appending the relative reference incorrectly.

 

1. My hosting account is under mesadesignhouse.com. The account name for it is mesacolo. I have my test domain, mdh-test.com, as **an add-on domain** under mesadesignhouse.com.

 

2. In my mdh-test.com account is a folder for php_training (mdh-test.com/php_training) (because this is my test domain and I'm testing Zen Cart and Drupal, which have been installed in mdh-test.com at the root level in their own directories).

 

3. In /php_training/ is an index.php and includes folder.

 

4. In the includes folder is style.css, header.html, and footer.html.

 

5. I'm entering http://mdh-test.com/php_training/index.php into the address bar.

 

The page title echo (included in the index.php file), footer, style sheet and style sheet are not being accessed.

 

If you click the link in #5, you'll see what I'm seeing.

 

The index.php code is:

 

<?php # Script 3.4 - index.php

$page_title = 'Welcome to This Site!';

include('includes/header.html');

?>

 

<h1>Content Header</h1>

 

  <p>This is where the page-specific content goes. This section, and the corresponding header, will change from one page to the next.</p>

 

  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec congue eleifend dui. Sed pellentesque. Integer rhoncus. In et neque a dui tincidunt lacinia. Nullam pharetra diam vitae sapien. Etiam dapibus porta elit. Integer aliquet, nibh in rhoncus suscipit, dolor urna feugiat eros, eu fermentum dui dolor eget felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque blandit. In leo. Etiam at elit quis leo iaculis auctor. Integer sed nulla vel velit molestie congue. </p>

 

<?php

include('includes/footer.html');

?>

 

Can anyone tell what I'm doing wrong, please? I have tried several incarnations of the paths, including what DW wants to do, and none of it is working. Ack!! Does it have something to do with my add-on domain on my hosting? I haven't had a problem with any of my other scripts, but then again, this is the first index.php page within a subfolder I've dealt with.

 

Theresa

 

Link to comment
Share on other sites

The styles is inside the header.html, I bet. How are you linking to it in there? paste the html for it please.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Page Title</title>

</head>

 

<body>

 

<div id="header">

<h1>Your website</h1>

        <h2>catchy slogan</h2> 

    </div>

   

<div id="navigation">

<ul>

    <li><a href="index.php">Home Page</a></li>

        <li><a href="calculator.php">Calculator</a></li>

        <li><a href="dateform.php">Date Form</a></li>

        <li><a href="#">Link Four</a></li>

        <li><a href="#">Link Five</a></li>

    </ul>

</div>

 

<div id="content"><!-- Start of the page-specific content. -->

 

<!--  Script 3.2 - header.html -->

 

Please tell me what else you need. The styles, header, and footer are all at the same level - in the includes folder that the index.php calls.

 

I figured out why the echo was not being seen. That was a no-brainer.

 

Link to comment
Share on other sites

<link rel="stylesheet" href="../includes/style.css" type="text/css" media="screen" />

 

You will also have to do that.

 

Nope, not working. Just tried it again. Like I said, I've gone up one level, I've gone up two levels. The header calls a file that is at the same level it is, because they're both in the includes folder. [i have since gotten the styles.css to be accessed by taking off the ../, leaving includes/style.css]. In the index.php file, it calls the header file and the footer file, which are both at the same level of each other. It sees one and says the other doesn't exist.

Link to comment
Share on other sites

Try using

 

$_SERVER['DOCUMENT_ROOT']

 

and

 

$_SERVER['HTTP_HOST']

 

and use those to give the absolute paths instead of the relatives. This is generally better anyhow.

 

I'm a PHP n00b on chapter **3** of the PHP book. Where would I put these? In the index.php file (I'm thinking that's a yes)? And before all the other content of the index page within the php tags? How do I put in absolute paths when I'm not sure what the paths are in the first place, or do those reference you put above suffice??

 

I'm completely discombobulated. Please forgive me for being dense. I'm not, usually.

Link to comment
Share on other sites

The best way to learn is trial and error. See what document_root spits out, and figure out how to put it into your code.

 

I could just write it for you, but then you do not learn.

 

Relative path means you use ../ etc so it is "relative" to your current position.

 

Absolute path means you link directly to each file IE: /home/www/user/includes/file.php

 

The absolute is preferred because then you can put your script in any folder and it should work.

 

Trial and error is one of the best ways to learn, although frustrating, when you figure it out you tend to know more about what to do and what not and it sticks with you.

Link to comment
Share on other sites

The best way to learn is trial and error. See what document_root spits out, and figure out how to put it into your code.

 

I could just write it for you, but then you do not learn.

 

Relative path means you use ../ etc so it is "relative" to your current position.

 

Absolute path means you link directly to each file IE: /home/www/user/includes/file.php

 

The absolute is preferred because then you can put your script in any folder and it should work.

 

Trial and error is one of the best ways to learn, although frustrating, when you figure it out you tend to know more about what to do and what not and it sticks with you.

 

I know what relative and absolute references are, so that helps. Absolutely *is* definitely easier. I don't mind trial and error. If I did, I wouldn't be teaching myself this stuff in the first place. Heck, I figured out why my echo wasn't working, all by myself. I just wanted to make sure I was putting the code in the right place. I'll probably be back, but I'm off to try and err. :-) Thanks!

Link to comment
Share on other sites

The best way to learn is trial and error. See what document_root spits out, and figure out how to put it into your code.

 

I could just write it for you, but then you do not learn.

 

Relative path means you use ../ etc so it is "relative" to your current position.

 

Absolute path means you link directly to each file IE: /home/www/user/includes/file.php

 

The absolute is preferred because then you can put your script in any folder and it should work.

 

Trial and error is one of the best ways to learn, although frustrating, when you figure it out you tend to know more about what to do and what not and it sticks with you.

 

Okay, "UNCLE!" Can you show me what it's supposed to be so I can review your code and figure out where I'm screwing up (also a way I learn, since I can compare what I did versus what it's supposed to be)? I'm getting a parse error of:

 

Parse error: syntax error, unexpected T_VARIABLE in /home/mesacolo/public_html/mdh-test.com/php_training/index.php on line 3

 

Here's my code:

 

<?php # Script 3.4 - index.php

$_SERVER['DOCUMENT_ROOT']

$_SERVER['http://mdh-test.com/php_training']

 

$page_title = 'Welcome to This Site!';

include('includes/header.html');

?>

 

<h1>Content Header</h1>

   

    <p>This is where the page-specific content goes. This section, and the corresponding header, will change from one page to the next.</p>

   

    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec congue eleifend dui. Sed pellentesque. Integer rhoncus. In et neque a dui tincidunt lacinia. Nullam pharetra diam vitae sapien. Etiam dapibus porta elit. Integer aliquet, nibh in rhoncus suscipit, dolor urna feugiat eros, eu fermentum dui dolor eget felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque blandit. In leo. Etiam at elit quis leo iaculis auctor. Integer sed nulla vel velit molestie congue. </p>

 

<?php

include('includes/footer.html');

?>

 

Again, this is an add-on domain (mdh-test.com) in my master domain (mesadesignhouse.com), a php_training folder within the add-on domain, and then the index.php file and includes folder within that folder.

 

Should I be putting the href into double quotes or parens, since it's a string? Since the test site is an add-on domain, is my href reference path incorrect?

 

<banging head against keyboard> I CAN be taught!

Link to comment
Share on other sites

<?php
define("SERVER_PATH", $_SERVER['DOCUMENT_ROOT'] . "/");
define("SERVER_URL", "http://" . $_SERVER['HTTP_HOST'] . "/");

include(SERVER_PATH . "includes/header.html");
?>

 

header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="<?php echo SERVER_URL; ?>includes/style.css" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Page Title</title>
</head>

<body>

   <div id="header">
       <h1>Your website</h1>
        <h2>catchy slogan</h2>   
    </div>
   
<div id="navigation">
   <ul>
       <li><a href="index.php">Home Page</a></li>
        <li><a href="calculator.php">Calculator</a></li>
        <li><a href="dateform.php">Date Form</a></li>
        <li><a href="#">Link Four</a></li>
        <li><a href="#">Link Five</a></li>
    </ul>
</div>

<div id="content"><!-- Start of the page-specific content. -->

<!--  Script 3.2 - header.html -->

 

Should get you the right results, note change header.html to .php so it can parse php.

Link to comment
Share on other sites

For some reason, I had ended my footer file with the extension .shtml - **S**html!!! Not supposed to put shtml files in the includes folder (I know enough to be dangerous).

 

I fixed the extension, and it all works. Also, for my echo for the page title, I had forgotten to put in the dollar sign at the beginning. I figured the latter thing out comparing the code I downloaded from the book's website and my code (oh yeah, I have that, don't I???), toggling back and forth between files (I do love DW's tab thing, though I mostly hand-code in this WYSYWYG editor). The former item I compared by looking (AGAIN!!) at the contents of my includes folder. I saw the rogue "s" and then slapped myself silly because I'm such a dork!

 

Premiso, you have been so generous with your time and knowledge. Thank you! One day I hope to be as generous with n00bs as you have been with me.

Link to comment
Share on other sites

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.