header(Location) but with keeping the old url?

Discussion in 'PHP' started by kuser, Apr 11, 2012.

  1. #1
    Is the possible to make an header(Location: /404.php); for example but to keep in the url the same old page... like /denise for example,etc?
     
    kuser, Apr 11, 2012 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    yes, do header( 'HTTP/1.0 404 Error' ); instead (i.e. don't send a Location: redirect)
     
    szalinski, Apr 11, 2012 IP
  3. kuser

    kuser Banned

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Yes, but some browsers will put their own add when they see an 404 status :(
     
    kuser, Apr 11, 2012 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    you could do something like this.
    
    
    // start output buffer
    ob_start();
    
    // some code here 
    
    // somewhere you need to indicate if you want to display a 404 or not
    // you could do it like this.
    
    if ($some_variable == 2) {
       $error = 404;
    }
    
    // check if you want to display a 404 on same url
    if ($error == 404) {
    
      // empty output buffer
      ob_clean();
    
      // include 404 error page
      include_once('404.php');
      
      // stop executing
      exit;
    
    }
    
    
    PHP:
    Haven't tested it so not sure if this would work but in theory it should.
     
    stephan2307, Apr 12, 2012 IP