2

I am trying to create a mysql query where it echo out the files from the database. Here, I want the computer to echo out the detail of the file if there is such id number input by user whereas if there is no such id number of the file then it has to echo out HTTP 404 error code.

I have used this code at the top of the page.

      <?php
        http_response_code(404);
       ?>

The above code says Call to undefined function http_response_code()

And also when I use this code in something like if statement true then echo or if false then http_response code. It doesn't work.

6
  • what version of php are you using? Commented Apr 8, 2014 at 14:31
  • @DanielA.White, I guess PHP 4!! How can I check the version of the PHP? Commented Apr 8, 2014 at 14:32
  • http_response_code() was added in PHP 5.4, so you're probably on an older version. Commented Apr 8, 2014 at 14:34
  • @MarcB, what if I am using PHP 4? Is there any other way to implement this task? Commented Apr 8, 2014 at 14:35
  • @SandeshMgr You're probably not on PHP 4, but rather 5.2 or 5.3. You can check by using phpinfo() or php -v within your ssh shell Commented Apr 8, 2014 at 14:42

2 Answers 2

4

if you are using >= php4.0 use :

header("HTTP/1.1 200 OK");

php >= 4.3

header(':', true, 404);

php >= 5.4

http_response_code(404);
Sign up to request clarification or add additional context in comments.

Comments

1

If you can't use http_response_code(), try this:

if (!$results) {
    header('HTTP/1.1 404 Not Found');
    require_once('errors/404.php');
    exit;
}

You need to create 'errors/404.php' and add some text there.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.