Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Help needed please. Dont know how to intergrate PHP to HTML template.

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #30212
    tomasjj11
    Member

    Hi

    I am no good at PHP and I would like to use the error page to handle all errors snippet from here: snippet from css-tricks. It is to be used on a template page I have for a site I’m producing. So like the title says how do I integrate the PHP into the HTML of this page.

    Any help would be highly appreciated.
    Tom

    #79810
    Chris Coyier
    Keymaster

    Points to note:

    1) The first part of that snippet is .htaccess code, not PHP, so you’ll need to put that in a file called .htaccess in the root of your website.

    2) Your example page is HTML, so that’ll need to have the file extention PHP and have PHP running on the server for it to work (or otherwise some fancy system for parsing HTML as PHP).

    #79747
    tomasjj11
    Member

    Thanks Chris

    I created a file called error.php with my template HTML and the snippets PHP. The PHP works but the HTML doesn’t show when it is called by the .htaccess file. So a dead link on the site is http://www.flow23.co.uk/newL2P/xhtml/lessons.html you can see what I mean there.

    The url to error.php is http://www.flow23.co.uk/newL2P/xhtml/error.php the HTML shows when you call it directly but not with the htaccess file.

    I must have put the PHP onto the page wrong. Any help on how to do it would be great.
    Tom

    #79736
    Bob
    Member

    Try wrapping PHP tags ( ) around the PHP code. So it will look like this:

    
    $status = $_SERVER;
    $codes = array(
    403 => array('403 Forbidden', 'The server has refused to fulfill your request.'),
    404 => array('404 Not Found', 'The document/file requested was not found on this server.'),
    405 => array('405 Method Not Allowed', 'The method specified in the Request-Line is not allowed for the specified resource.'),
    408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
    500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
    502 => array('502 Bad Gateway', 'The server received an invalid response from the upstream server while trying to fulfill the request.'),
    504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
    );

    $title = $codes[$status][0];
    $message = $codes[$status][1];
    if ($title == false || strlen($status) != 3) {
    $message = 'Please supply a valid status code.';
    }
    // Insert headers here
    ?>

    Also, I see you left out the bit on headers in the code, I think you need that. So add the following code:

    echo '

    '.$title.'


    '.$message.'

    ';

    right between the line with //Insert headers here and the ?> php closing tag.

    #79609
    tomasjj11
    Member

    Thankyou Bob really helpful
    I think I might nearly be there now. When you go to http://www.flow23.co.uk/newL2P/xhtml/error.php the correct text comes up in the correct place. But still when you go to a dead link the HTML doesn’t show up :S I still must be doing something wrong. Any Clue?

    #79484
    Bob
    Member

    Show your .htaccess code, and where did you put it? In the root folder?

    #79485
    tomasjj11
    Member

    My .htaccess file is in the folder below xhtml which is the root folder of this site. The link is http://www.flow23.co.uk/newL2P/.htaccess. It looks exactly the same as the one supplied by Chris on the snippets page. Does it need to be with the html files in the xhtml folder?

    btw Thanks for the DropBox referral link I’ve signed up now :D

    #79486
    Bob
    Member

    I believe you have to put it in the root folder of your site, ’cause otherwise it will only work for that directory. Or so I’ve heard, not totally sure about it but I’d try putting it in the root, so that the link would be http://www.flow23.co.uk/.htaccess. Also, are you sure the filename is .htaccess? So no words are before the dot?

    You’re welcome for the dropbox link, and thank you too :D

    #79489
    tomasjj11
    Member

    The file is defiantly only .htaccess there are no words before the dot. Also the root http://www.flow23.co.uk/.htaccess is a different website to this one. The root is home to my personal site this one is a clients site which is hosted on the same server and the url is pointed to that folder as being its root so where it is at the moment is the root for that site.

    In hindsight it would seem that me being lazy, and not just making some html pages with the writing on which the .htaccess points to serperatly, was a bad decision. So if we can’t get this working thats what i will do.

    I didn’t realise how much you could do with that drop box. I’m at University will come in really handy when I’m collaborating on projects.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Back End’ is closed to new topics and replies.