Page 1 of 1

heres one for you clever guys out there, error404.html help

Posted: Tue May 29, 2007 9:05 pm
by ianhull
Hi guys,

I got a little issue,

I have a custom error404.html

I only have one other page on my site, index.html

Please note .html extention is enabled to use php

All my pages come from the database, depending on the url.

Here is what I have,

Code: Select all


<?php session_start();

    include_once($_SERVER['DOCUMENT_ROOT'].'/includes/connection.html');

    $domain_name = $_SERVER['HTTP_HOST'];
    
	$page_name = str_replace('/', '', $_SERVER['SCRIPT_NAME']);

    $getPage = mysql_query("SELECT
	id,
	company_name,
	company_email,
	domain_name,
	page_name,
	page_details,
	page_template,
	create_date,
	modify_date FROM website_pages WHERE domain_name = '$domain_name' AND page_name = '$page_name' LIMIT 1")or die(mysql_error());

    if(mysql_affected_rows() == 0){
	
	$page_template = $_SERVER['DOCUMENT_ROOT'].'/css/standard/';
    include_once($_SERVER['DOCUMENT_ROOT'].'/includes/404.html');
	exit();
	
    };
	
	echo '<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
';
	
	while($pageRecieved = mysql_fetch_array($getPage)){
	extract($pageRecieved);
	}
	
	$page_title = substr($page_details,0,30);
	
	$page_keywords = substr($page_details,0,600);
	
	$page_description = substr($page_details,0,100);
	
	echo '<base href="http://'.$_SERVER['HTTP_HOST'].'/" />
<link href="css/'.$page_template.'.css" rel="stylesheet" type="text/css" />
<title>'.$page_title.'</title>
<meta http-equiv="imagetoolbar" content="no" />
<meta name="keywords" content="'.$page_keywords.'" />
<meta name="description" content="'.$page_description.'" />
<meta name="copyright" content="'.$company_name.'" />
<meta name="owner" content="'.$company_email.'" />
<meta name="language" content="en-gb" />
<meta name="rating" content="general" />
<meta name="robots" content="index,follow" />
<meta name="revisit-after" content="7 days" />
<meta name="author" content="ian@domain" />
<meta name="expires" content="never" />
</head>

<body>
<div id="logo"><img src="company_logos/'.$company_name.'" alt="'.$company_name.'" /></div>

<div id="content">'.$page_details.'</div>

<div id="navigation">
<img src="images_'.$page_template.'/navigation_top.jpg" alt="Website Navigation" width="200" height="42" />
';

include_once($_SERVER['DOCUMENT_ROOT'].'/includes/navigation.php');
echo '
</div>

</body>
</html>';

?>

this works just fine, for the index.html,

here is my navigation file.

Code: Select all


<?php

    $getNavigation = mysql_query("SELECT
	domain_name,
	page_name FROM website_pages WHERE domain_name = '$domain_name'")or die(mysql_error());
	
	while($navigationRecieved = mysql_fetch_array($getNavigation)){
	extract($navigationRecieved);
	
	$page_name = str_replace('.php', '', $page_name);
	
	if($page_name == 'index'){
	$page_name = 'Home';
	}
	
	echo '<p><a href="'.$page_name = strtolower(str_replace(' ', '-', $page_name)).'.php">'.$page_name.'</a></p>
';
}
?>

This also works, but it creates link to pages that do not exist, for example.

home.php
contact us.php

This is why I would like my custom error404.html page to retrieve the requested filename.

for example,

http://www.domain.com/get-me-this-page.html

but god knows how to do it.

I am hoping one of you guys can help me achieve this,

All I am recieving at the moment is, /index.html when the error404.html is included.
I really need to recieve the /what-ever-page.html so that I can query the database and get the needed info.

I am not interested in mod_rewrite or anything like that so suggestions for that are out of the window :)

My main objective is to build a website using 3 pages.

index.html
connection.html
error404.html

Thanks guys

Posted: Tue May 29, 2007 9:14 pm
by nyfael
I was going to suggest mod_rewrite so I'll just stop there.

I'm mainly curious. Why?

Posted: Tue May 29, 2007 9:19 pm
by ianhull
Why i dont want to use mod_rewrite or why I would like to make a 3 page website?

Well, mod_rewrite I find complicated, I tried it so many times and never got it working.

I would like to make a 3 page website, and then get it to a 1 page website which supports, multiple companies and domains, shopping carts, and any new module I make.

I have some spare time now so this is what I would like to do, once it's done there's no messing when i take on board a new company.

I just simply login to my control panel, add a new domain/company etc, give them access to a website or a shopping cart, calendar etc.

Ian

Posted: Tue May 29, 2007 9:25 pm
by mattkenefick
have you tried javascript to get the window location? or what was put in the address bar?

Posted: Tue May 29, 2007 9:28 pm
by mattkenefick
if the javascript works


option1:
you could have it redirect to like..

http://whatever.com/fake-page.html

=

http://whatever.com/?s=fake-page



option2:
or set it to a cookie and have it reload the page. then when the PHP loads and sees the cookie is set, it'll display whatever is set in the cookie.



theres actually plenty options you could do if the JS works.


-------------------------
If it doesnt work...

Could you get the HTTP Referrer on the error page to see where they came from? Maybe that'll give you the link they tried to use. Then put that through whatever Switch statement or DB Query you have setup to include the correct information.

Posted: Tue May 29, 2007 10:16 pm
by ianhull
Thanks Matt,

this is now startig to be a pain, maybe I should look at mod_rewrtie again :)

Your suggestion for page?var=whatever etc would work, but I need it to be seo friendly and do not want to use ?var=etc

_________________________

I have just had a look at mod_rewrite again but this is what I have

RewriteEngine on
RewriteRule ^/([^/\.]+).html$ index.php [L]

All I want to do is redirect all links to index.php or .html

If I do this do my links still have to contain ?var=etc

What I mean by this is <a href="'.$page_name.'>'.$page_name.'</a>
I need to look like <a href="home.html>Home</a>

Not<a href="index.html?page=home>Home</a>

thanks

Posted: Wed May 30, 2007 12:48 am
by RobertGonzalez
Get rid of the assignment in the str_replace call.

Edit | now that I think about it, you could do:

Code: Select all

<?php
$getNavigation = mysql_query("SELECT
        domain_name,
        page_name FROM website_pages WHERE domain_name = '$domain_name'")or die(mysql_error());
       
    while ($row = mysql_fetch_array($getNavigation)) {
        $page_link = $row['page_name'];       
        $page_name = str_replace('.php', '', $page_link);
       
        if ($page_name == 'index') {
            $page_name = 'Home';
        }
       
        echo '<p><a href="'.strtolower($page_link).'">'.$page_name.'</a></p>';
}
?>

Posted: Wed May 30, 2007 1:48 am
by John Cartwright
I would prefer using basename() over str_replace in this case

Posted: Wed May 30, 2007 10:58 am
by RobertGonzalez
Probably not a bad idea Jcart.

Posted: Wed May 30, 2007 12:57 pm
by nyfael
That will make any page not found be directed to the one you specified. I use it on pretty much every website I make.

.htaccess

Code: Select all

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /error404.php
This PHP code will tell you what page you're on:

Code: Select all

$_SERVER["REQUEST_URI"]

Posted: Wed May 30, 2007 1:09 pm
by Ollie Saunders
ianhull, could you explain (without using code) what it is you are trying to achieve and how 404 fits into this.