3

I'm a pretty new PHP programmer, and as I was trying to call the PHP http_redirect() function, this error came up:

Fatal error: Call to undefined function http_redirect() in D:\xampp1.8.3\htdocs\Bank\create.php on line 28

I called it just like they did in the examples on the php site like this:

http_redirect("show.php", array("status" => "new"), true, HTTP_REDIRECT_PERM);

I'm more familiar with header(), but I don't know how to send in an something similar to http_redirect()'s params (the array()). I've tried doing header("Location: show.php?status=new") but that doesn't work for me.

Could somebody help with this? Thanks.

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
  • 5
    Do you have `pecl_http` installed? `http_redirect` is provided in the PECL `pecl_http` package as stated in the link you've posted, but the `header("Location:...")` should work. Can you post more code where you are using the `header` function. – vee Aug 09 '13 at 02:32
  • And if `header()` [doesn't work](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php), so won't `http_redirect()`. A userland fallback is available in upgradephp. – mario Aug 09 '13 at 02:38
  • 1
    Try an absolute url in your header("Location:") command. And make sure you did not output anything before that. – ToBe Sep 25 '13 at 13:46

1 Answers1

1

http_redirect is also sending the same headers for location like you tried, so you don't really need http_redirect

  1. Your error is http_redirect does not exist, so I think you don't have pecl_http installed like @vinodadhikary said
  2. If header("Location ...") is not working maybe your headers are already sent (you can check this with the function headers_sent

    • Example: if(!headers_sent()) header("Location http://YOURDOMAIN.abc/target.html");
  3. It is suggested to use absolute URLs for location header

  4. In a comment on php.net, Chrome doesn't perform a Location: instruction unless it gets a Status: first
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
Radon8472
  • 4,285
  • 1
  • 33
  • 41