Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-10-06 04:43:23

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Apache headers and Textpattern

This is for a Textpattern site hosted at TextDrive.

I like to redirect successful form submissions to a thank you url. I am guessing it is Textpattern’s 200 OK header that is interfering, but I don’t know for certain. What happens is I get a blank page, the title is 200 OK, and the text “the document has moved here” with a link to the url I wanted the user to be redirected to.

How can I override the previously sent header, what would I send instead?

Offline

#2 2005-10-06 05:31:13

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Apache headers and Textpattern

You can replace a header by sending it again. Textpattern already does this in its 404 handling.

Most likely you’re sending a Location header without also setting the status to 301 or 302. Use txp_status_header() if you can, to avoid fcgi problems.


Alex

Offline

#3 2005-10-06 05:39:14

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: Apache headers and Textpattern

You can replace a header? Either a) I’m confused about what you’re trying to do or b) I’m needing much more instruction in PHP. I always thought you could only send headers once. Or wait, does this not apply when using ob_start()?

Last edited by Andrew (2005-10-06 05:42:57)

Offline

#4 2005-10-06 06:20:58

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Apache headers and Textpattern

You can’t send headers after page output has started – txp uses ob_start() to get around this.

Before the page output starts, you can send each header multiple times; only the last one counts. The header() manual page confirms this (there’s now an extra param that lets you control it).


Alex

Offline

#5 2005-10-06 06:31:51

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: Apache headers and Textpattern

Learn something new every day. Thanks, z.

Offline

#6 2005-10-06 08:01:05

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Apache headers and Textpattern

Hi mary,

there is basically two ways to send the http-response-code: starting with “HTTP/1.1 “ and “Status: “, depending on how PHP is installed only one them may really work. (The result you are describing leads me to believe you used the wrong one for your case).

Hence why I put in both in earlier versions. In newer versions (it’s been in SVN for a while), we’ll do a proper check first to decide which one to send. And any plugin that changes the response-code (which you need to do for redirects) should do it that way as well.

See:
http://forum.textpattern.com/viewtopic.php?pid=79864#p79864
for a one-liner workaround that you can use right now.

In future releases and in svn you can already use a function call as in this example:
http://dev.textpattern.com/changeset/895

Offline

#7 2005-10-06 09:00:13

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Apache headers and Textpattern

Thanks very much guys, that was an enlightening and absurdly simple fix. I didn’t understand the reasoning about the use of status before, having never run into this problem before – I always had PHP provided to me via the Apache module. I had tried sending 303, two different ways, both with the same yucky result:

<pre><code>header(“HTTP/1.1 303 See Other”);
header(“Location: http://domain.com/page”);</code></pre>

<pre><code>header(“Location: http://domain.com/page”, true, 303);</code></pre>

Using Status was what I needed:

<pre><code>header(“Status: 303 See Other”);
header(“Location: http://domain.com/page”);</code></pre>

Thanks again!

Offline

Board footer

Powered by FluxBB