+ Reply to Thread
Results 1 to 3 of 3

Thread: Die to location?

  1. #1
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Die to location?

    Is there an easy way to exit a PHP script and show a separate document without changing the URL, something similar to a 404 error page? Like die("location: 404.html") or something like it?

  2. #2
    gptsven is offline x10 Lieutenant gptsven is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    253

    Re: Die to location?

    Something like this:


    PHP Code:
    $id 1;
    $page 'pagename';
    $query "SELECT * FROM news WHERE id=$id";

    // check if the record excists.

    $result mysql_query($query); 

    if ( 
    $result === false 
    {
      
    header("location:error.php?refferer=$pagename&errorcode=5")
    }
    else
    {
      
    /// print page with news 

    just make a new database that holds different errorcodes and print a suitable message depending on the errorcode. also make another sql database that stores the frequency of errors ocuring, on what page ($pagename)

    never use "or die();" only if you see that your query doesnt work to get debugging results to find the error

    or did you mean something else?

    you can also store data in sessions and use that in error.php
    Last edited by gptsven; 04-19-2009 at 02:04 PM.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Die to location?

    I assume you don't want the URL to change because you're simulating an error page.

    What you're describing is an internal redirect, which (as far as I can tell) isn't an option within PHP. What you can do is write no output from the script and include() (or virtual()) the error document. The standard approach would be to test at the top of the script anything that would fatally prevent the script from running. That way you don't need to worry about wasted processing or accidentally writing out data. Just to be safe, you still might want to use output buffering.

    If you're including an HTTP error page, I recommend using a scripted page so it can set the appropriate Status header.

    404.php:
    PHP Code:
    <?php
    $statusCode
    =404;
    $statusName='Not Found';
    $title='Page does not exist...';

    // simple URL correction: find the longest head section of the URL that is a valid page
    if (function_exists('apache_lookup_uri')) {
        
    $uri $_SERVER['REQUEST_URI'];
        do {
            
    $uri dirname($uri);
            
    $uri_info apache_lookup_uri($uri);
        } while (
    $uri_info->status >= 400 && $uri && $uri != '/');
    }

    $errorMessage=<<<EOF
    <p>The page you requested ({$_SERVER['REQUEST_URI']}) does not exist, you can try visiting this site&apos;s home page below.<br />
      <span style="font-size:26px;"><a href="http://
    {$_SERVER['HTTP_HOST']}/" class="Link">http://{$_SERVER['HTTP_HOST']}/</a></span>.
       </p>
    EOF;

    include(
    'err.php');
    ?>
    err.php:
    PHP Code:
    <?php
    if (! isset($errorCode)) {
        
    $errorCode $_SERVER{'REDIRECT_STATUS'};
    }
    header("Status: $statusCode $statusName");
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    ...
    Last edited by misson; 04-19-2009 at 02:16 PM.

+ Reply to Thread

Similar Threads

  1. X10Hosting Gamer Tag Listing
    By Kayos in forum Gamer's Lounge
    Replies: 82
    Last Post: 01-09-2012, 02:42 AM
  2. SQL Database location?
    By martynball in forum Programming Help
    Replies: 4
    Last Post: 05-15-2008, 12:20 PM
  3. Replies: 3
    Last Post: 05-10-2008, 12:05 AM
  4. You want to know the the Visitor location?
    By satheesh in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 12-26-2007, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers