Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Page not displaying - include
Old 02-20-2008, 07:22 PM Page not displaying - include
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Hello,

I'm new to php and have just discovered the include function. I'm using php to include a few files on a page.

Although, the page does not display. I view the source and this is what is there.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
I try two different ways of coding my page, one completely php (using echo to show HTML) and the other one using html, with php to include the files (HTML <?php include() ?> HTML). However both have the same results.

This is the first code.

PHP Code:
<?php 

include ('config.php');  

echo 
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>'
;

include (
$inc."css.php"); 

echo 
'<title>'.$title.'Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<center>
<div id="main">'
;

 include (
$inc.'header.php');  

echo 
'<div id="body">
          
          
          <div id="left">
              
                      <div class="title">

                      <h2>Left</h2>
                      
                      </div>
            
               <p>This is where the content for the left hand side would go, or posibally another menu...</p>
              
          </div>
          
          <div id="middle">
               
                    <div class="title">
                    
                    <h2>Middle</h2>
                    
                    </div>
                
                <p>This is where the content for the middle part would go, this may be an introduction to the site or anything along the lines of that. </p>
            </div>
            
            <div id="right">
            
                 <div class="title">
                 
                 <h2>Right</h2>
                 
                 </div>
            
            <p>This is where the content for the right hand side would go. </p>
            
            
            </div>
            
            
     </div>


</div>

</center>
</body>
</html>'
;
and this is the second code:

PHP Code:
<?php 

include ('config.php');  ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<?php 
include ($inc."css.php"); ?>

<title><?php echo $title ?>Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<center>
<div id="main">
<?php

 
include ($inc.'header.php');   ?>

<div id="body">
          
          
          <div id="left">
              
                      <div class="title">

                      <h2>Left</h2>
                      
                      </div>
            
               <p>This is where the content for the left hand side would go, or posibally another menu...</p>
              
          </div>
          
          <div id="middle">
               
                    <div class="title">
                    
                    <h2>Middle</h2>
                    
                    </div>
                
                <p>This is where the content for the middle part would go, this may be an introduction to the site or anything along the lines of that. </p>
            </div>
            
            <div id="right">
            
                 <div class="title">
                 
                 <h2>Right</h2>
                 
                 </div>
            
            <p>This is where the content for the right hand side would go. </p>
            
            
            </div>
            
            
     </div>


</div>

</center>
</body>
</html>
config.php contains.

PHP Code:
<?php 

// Main title

$title 'S Gilligan :: ';

// Stylesheet URL

$css "http://www.sgilligan.co.uk/css/style.css";

// URLS for menu

$home "http://www.sgilligan.co.uk";
$tools "http://www.sgilligan.co.uk/tools";
$downloads "http://www.sgilligan.co.uk/downloads";

// Images

$mainlogo "http://www.sgilligan.co.uk/images/mainlogo.png"

// Include main URL

$inc "http://www.sgilligan.co.uk/includes/";

?>
includes/css.php contains

PHP Code:
<?php

echo '<link rel="stylesheet" type="text/css" href="http://www.sgilligan.co.uk/css/style.css">';

?>
and includes/header.php contains

PHP Code:
<?php 

include ("./config.php");

echo 
'<div id="header">

<center>

<img src="'
.$mainlogo.'" alt="S Gilligan.co.uk">

</center>'


include (
$inc.'tabs.php');

echo 
'</div>';

?>
Sorry for the long post but its the only way I could get all the information across. I'd rather give too much info instead of too little.

Can someone help me to explain why this is happening.

Thanks in advance for any assistance.

Gilligan

Last edited by Gilligan; 02-20-2008 at 07:26 PM..
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-20-2008, 07:48 PM Re: Page not displaying - include
Ultra Talker

Posts: 483
Trades: 0
Long story short, by having that $inc variable with the http://blahblah at the start, you end up trying to include via HTTP which is not what you want.

99 times out of 100, when you include you want to include from the file system, not via HTTP. You probably want to set $inc to something like 'includes/' instead.
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 02-21-2008, 01:21 AM Re: Page not displaying - include
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Better set $inc to something like $_SERVER['DOCUMENT_ROOT'].'/includes/'
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-21-2008, 06:36 AM Re: Page not displaying - include
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Tried $_SERVER['DOCUMENT_ROOT'] and got this error

Warning: include() [function.include]: open_basedir restriction in effect. File(/usr/local/apache/htdocscss.php) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/a5839198/public_html/index.php on line 10

And I tried '/includes/' but got this error

Warning: include(/includes/css.php) [function.include]: failed to open stream: No such file or directory in /home/a5839198/public_html/index.php on line 10

Even if I try replacing line 10 with

Code:
<?php include ("/includes/css.php"); ?>
I still get the second error.
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 02-21-2008, 06:43 AM Re: Page not displaying - include
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Holy sht, who is your hoster?

In this case you should define your starting point as /home/a5839198/public_html/ and resolve your paths from it.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-21-2008, 06:52 AM Re: Page not displaying - include
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Okay, for some reason its started to work.

All I did was make $inc = './includes/'
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 02-21-2008, 07:06 AM Re: Page not displaying - include
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
Holy sht, who is your hoster?

In this case you should define your starting point as /home/a5839198/public_html/ and resolve your paths from it.
Sorry, new at php.

Do you mean set $inc = '/home/a5839198/public_html/includes';

I tried this before and it failed miserably

[EDIT]Just tried it and it worked [/EDIT]
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 02-22-2008, 02:50 AM Re: Page not displaying - include
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
It could fail for only reason. You say include ($inc."css.php"), and if you define $inc without trailing slash the whole path will become invalid. I recommend you always have your paths without trailing slash and always attach your relative paths to predefined paths with leading slash:
PHP Code:
$inc '/usr/www/mysite';
...
require 
$inc.'/somefile.php'
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!

Last edited by mtishetsky; 02-22-2008 at 02:51 AM.. Reason: Forgot the quotes
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Page not displaying - include
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30973 seconds with 12 queries