views:

685

answers:

3

Hi,

I'm trying to use the header() function to create a redirect. I would like to display an error message. Currently I'm sending the message as a parameter through the URL, however this makes it look quite ugly.

Is there a way to pass this value as a post variable instead?

Any advice appreciated.

Thanks.

+1  A: 

The header function is used to send HTTP response headers back to the user so actually you cannot use it to create request headers :(

One possibility is to use the CURL but I don't think it is worth of what you are doing.

Sarfraz
+5  A: 

Dan, You could start and store a session in PHP and save the message as a session variable. This saves you from having to transfer the message in an HTTP request.

To read more about sessions, check out: http://php.net/manual/en/function.session-start.php

EDIT: To clarify, you would start the session in your page, save the message in a session variable and then use header() to redirect the location to your error page where you would then start the session again and read the session variable.

ocdcoder
Simple and easy
Andy
+1  A: 

Provided that you have local access to the page displaying the error, instead of redirecting you could include it in the page which caused the error and then programmatically display the error message.

if(something_went_wrong()) {
  require_once('errors.php');
  display_error('something really went wrong.');
  }

The errors.php file would then contain a definition for display_error($message), which displays the formatted message.