Log in

View Full Version : PHP Includes



Shibby-Shabs
02-09-2009, 11:05 AM
I have my site working on php includes and I created a page that has cutenews embeded on it and it works fine on there but it shows the error message.

eg.
ERROR! page not found!

Heinous
02-09-2009, 11:07 AM
Try echoing out where you're looking for it.

change; include to echo.

You're probably looking in the wrong directory for it.

Shibby-Shabs
02-09-2009, 11:21 AM
Ok sorry i forgot to mention I don't know PHP so make it easier

Heinous
02-09-2009, 11:34 AM
Where is "Error: not found" generated in? Unless it's a PHP error, in which case it'll be "line XX in file.php", if so, paste that segment of the file please.

(removing any sensitive data if required)

Shibby-Shabs
02-09-2009, 11:40 AM
heres the whats inside the document where when viewed in index.php?page=title.php


<html>
Computer tutorials are posted here, they may be text, images or photos. If you need help and want to request a tutorial use the contact us form on the contact page!
<?PHP
$category=2;
include("/home/zipped/public_html/site/backend/show_news.php");
?>
</html>
Yes not all tags are there because they arn't really needed.

Heinous
02-09-2009, 11:42 AM
Is..


include("/home/zipped/public_html/site/backend/show_news.php");the line that's giving you the file not found error? If so, check it exists at that ^ location.

Also I hate using absolute directories (unfortunately sometimes required), try using a relative path.

Shibby-Shabs
02-09-2009, 11:51 AM
http://zippedfiles.co.cc/site/index.php?page=tutorials_pc
Username: zipped
password: jack123

Heinous
02-09-2009, 12:43 PM
http://zippedfiles.co.cc/site/index.php?page=tutorials_pc
Username: zipped
password: jack123
Cutenews works, and doesn't look like a cutenews error?

Shibby-Shabs
02-09-2009, 12:46 PM
I Know, it has to do with the site... any ideas..?

Oh and incase you know, why when index.php is visited is it blank and not showing home.php?

Heinous
02-09-2009, 12:50 PM
Either PM me or post the PHP code for index.php, and I'll have a look at both.

Shibby-Shabs
02-09-2009, 01:03 PM
<!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 profile="http://gmpg.org/xfn/11">
<title>Zipped Files | Downloads | Tutorials | Hosting</title>
<link rel="icon" href="image/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="en-gb" />
<meta http-equiv="imagetoolbar" content="false" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="author" content="Christopher Robinson" />
<meta name="copyright" content="Copyright (c) Christopher Robinson 2005 - 2007" />
<meta name="description" content=""/>
<meta name="keywords" content="" />
<meta name="last-modified" content="Thursday, 01 February 2007 12:00:00 GMT" />
<meta name="mssmarttagspreventparsing" content="true" />
<meta name="robots" content="index, follow, noarchive" />
<meta name="revisit-after" content="7 days" />
</head>

<body>
<div id="container">
<div id="navigation">
<ul>
<li><a href="index.php?page=contact">Contact</a>
<li><a href="index.php?page=login">Login</a>
<li><a href="index.php?page=tutorials">Tutorials</a></li>

<li><a href="index.php?page=hosting">Hosting</a></li>
<li><a href="index.php?page=download">Downloads</a>
<li><a href="index.php?page=home">Home</a>
</div>
<div id="content">



<br>
<?php
if (!isset($page))
{
include("blank.php");
}
if(file_exists($_GET['page'].".php")){
include $_GET['page'].'.php';
}
if(file_exists($_GET['page'].".html")){
include $_GET['page'].'.html';
}
if(file_exists($_GET['page'].".txt")){
include $_GET['page'].'.txt';
}
if(file_exists($_GET['page']."folder/.php")){
include $_GET['page'].'/system/login.php';
}
elseif (isset($page) && !@include("$page"))
{
echo "Error Page not found!";
}
?>




</div>
<div id="footer">
<center>Zipped Files - 2009</a>
&nbsp;&nbsp;|&nbsp;&nbsp;
Designed by <a href="http://www.edg3.co.uk/" title="Freelance Web Site Design">edg3.co.uk</a>

</div>
</div>
</body>
</html>

Heinous
02-09-2009, 01:10 PM
elseif (isset($page) && !@include("$page"))Incorrect usage of include.

Use file_exists (http://php.net/file_exists) instead.

Also, change the elseif to just an if. There's too many if statements there for it to be executed correctly.

edit:
oh and it displays a blank page because of this line..

include("blank.php");

Fehm
02-09-2009, 01:11 PM
include("backend/show_news.php");


Try changing it to the relative link as oppose to the other kind :P

If it doesn't work, im sorry xD

Shibby-Shabs
03-09-2009, 08:26 AM
Incorrect usage of include.

Use file_exists (http://php.net/file_exists) instead.

Also, change the elseif to just an if. There's too many if statements there for it to be executed correctly.

edit:
oh and it displays a blank page because of this line..
So like

if (file_exists($filename)) {



include("backend/show_news.php");


Try changing it to the relative link as oppose to the other kind :P

If it doesn't work, im sorry xD

Thanks Iapps but cutenews it working fine!

Heinous
03-09-2009, 08:33 AM
Um, more or less..


elseif (isset($page) && !@include("$page")) {
becomes..

if (isset($page) and file_exists($page) === false) {

Shibby-Shabs
03-09-2009, 08:39 AM
Made the change and still "page not found"

Heinous
03-09-2009, 09:01 AM
<?php
if (isset($_GET['page']) === true) {
$page = stripslashes($_GET['page']);
if (file_exists($page . '.php') === true) {
include $page . '.php';
} elseif (file_exists($page . '.html') === true) {
include $page . '.html';
} elseif (file_exists($page . '.txt') === true) {
include $page . '.txt';
} else {
echo 'Error: page not found.';
}
} else {
include('blank.php');
}
?>
Replace your current PHP code with that. It's more efficient and.. correct. Let me know if it still occurs afterwards.

Shibby-Shabs
03-09-2009, 09:08 AM
Thank you for your help, it doesn't occur anymore.. one last thing say in the navigater I had index.php?page=foo which is in the same directory as index, title as foo.php how would I link to say /folder/file.php ?

Heinous
03-09-2009, 09:36 AM
index.php?page=/folder/file

Should work.

Shibby-Shabs
03-09-2009, 10:01 AM
Ok that doesn't work and also when I load index.php it shows blank content instead of home.php

Heinous
03-09-2009, 10:13 AM
http://zippedfiles.co.cc/site/index.php?page=system/login

Works. Don't have a backslash at the start.

And change include('blank.php') to home.php

Shibby-Shabs
03-09-2009, 11:29 AM
ok thank you
EDIT: Doesn't work, when you press login it goes to /site/login.php

Heinous
03-09-2009, 12:24 PM
You have to modify your actual PHP files to use the index.php?page=XXXXX system.

Want to hide these adverts? Register an account for free!