Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-04-15 18:20:52

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Why can I not use PHP redirects in Textpattern?

Hi,

Why can I not use this at the top of my search page?

The intended behavior is to redirect my local /search/?q=SEARCH&hos=sesam to http://sesam.no/search/?q=SEARCH.

<txp:php>if ($_GET["hos"] == "sesam" ]) {
$finn = $_GET["q"];
header("Location: http://sesam.no/search/?q=$finn");
} </txp:php>

The error output of the code is:

Parse error: parse error, unexpected ‘]’ in /home/content/a/l/e/aleksandersen/html/www/aleksandersen/textpattern/publish/taghandlers.php(2681) : eval()’d code on line 1

Last edited by Aleksandersen (2007-04-15 18:23:46)

Offline

#2 2007-04-15 19:03:17

wet
Developer Emeritus
From: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,391
Website GitHub Mastodon

Re: Why can I not use PHP redirects in Textpattern?

Because there’s an excess, thus unexpected ‘]’ after "sesam".

Corrected code:

<txp:php>if ($_GET["hos"] == "sesam" ) {
$finn = $_GET["q"];
header("Location: http://sesam.no/search/?q=$finn");
} </txp:php>

Offline

#3 2007-04-15 19:26:01

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Why can I not use PHP redirects in Textpattern?

Oh, thanks for noticing! But it still does not work.

It gets a 200 OK responds, and will not accept 301, 301, nor 303 (preferred).

/finn/?q=Morgenbladet&finn=nett (plain PHP)

<txp:php>if ($_GET["finn"] == "nett" ) {
$finn = $_GET["q"];
header("HTTP/1.1 303 See Other");
header("Location: http://sesam.no/search/?q=$finn");
} </txp:php>

Last edited by Aleksandersen (2007-04-15 22:22:52)

Offline

#4 2007-04-15 22:08:43

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

Re: Why can I not use PHP redirects in Textpattern?

Make sure your code works as a plain PHP script first. Some servers and PHP versions are fussy about location and status headers.


Alex

Offline

#5 2007-04-15 22:20:35

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Why can I not use PHP redirects in Textpattern?

It works just fine as plain PHP.

Offline

#6 2007-04-15 22:25:36

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Why can I not use PHP redirects in Textpattern?

Does your webserver use mod_php, plain CGI or fast-cgi for PHP files?

Offline

#7 2007-04-15 22:42:05

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Why can I not use PHP redirects in Textpattern?

I have no idea. I am using GoDaddy hosting.

Offline

#8 2007-04-15 23:49:57

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

Re: Why can I not use PHP redirects in Textpattern?

Try debugging. Make sure your code runs. Call txp_status_header() instead of header("HTTP/1.1 303 See Other");. Put your code in a plugin instead of the page template.

If none of that helps, you may have encountered one of many undocumented and bizarre quirks in PHP’s header() function.

Last edited by zem (2007-04-15 23:51:17)


Alex

Offline

#9 2007-04-17 00:09:36

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

Re: Why can I not use PHP redirects in Textpattern?

Try adding to the end of your PHP:

header("Connection: close");

Offline

#10 2007-04-17 00:22:04

Aleksandersen
Member
From: Lillehammer, Norway
Registered: 2007-04-12
Posts: 77

Re: Why can I not use PHP redirects in Textpattern?

I added die; at the end instead. Did not help.

Offline

#11 2007-04-17 01:19:50

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

Re: Why can I not use PHP redirects in Textpattern?

Did you debug? Check your diagnostics?


Alex

Offline

#12 2007-04-20 19:01:29

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Why can I not use PHP redirects in Textpattern?

I use the following bit of code for a redirect on one of my sites hosted at GoDaddy…

Header (“Refresh: 0;url=[url]”);

I will be glad to send you the whole bundle of php spaghetti I use if you like.

Offline

Board footer

Powered by FluxBB