Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-07-16 18:52:20

NyteOwl
Member
From: Nova Scotia, Canada
Registered: 2005-09-24
Posts: 539

Odd behaviour using txp:php

I ran into some odd behaviour when trying to include a script on a page.

If I use txp:pgp to include a script, eg. <code><txp:php> virtual (“/cgi-bin/tdp.cgi”); </txp:php></code>, it writes the script output to the upper left corner of the page before rendering the rest of the page (and without any styling from the container tags).

If I use a regular PHP tag, eg. <code><?php virtual (“/cgi-bin/tdp.cgi”); ?></code>, it properly inserts the code output at the location of the tag in the page.

Has anyone run into this before?


Obsolescence is just a lack of imagination. / 36-bits Forever! / #include <disclaimer.h>;

Offline

#2 2006-07-17 01:23:33

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

Re: Odd behaviour using txp:php

Probably something to do with output buffering. txp:php is executed during page parsing; old-style php tags are executed after the page is complete.

In my experience, virtual() is too unreliable for most purposes. It acts in unpredictable ways, particularly regarding $_SERVER variables.

Last edited by zem (2006-07-17 01:59:53)


Alex

Offline

#3 2006-07-17 17:54:25

NyteOwl
Member
From: Nova Scotia, Canada
Registered: 2005-09-24
Posts: 539

Re: Odd behaviour using txp:php

Hi zem, thanks for the info!

I’m not great with PHP (still learning), is there a better way to do the script insertion? I’m converting a static html page and it was originally done via SSI.

In thinking about it, if txp:php is parsed as the page is processed, then it should appear where the tags are located in the page, shouldn’t it?

Last edited by NyteOwl (2006-07-17 21:28:23)


Obsolescence is just a lack of imagination. / 36-bits Forever! / #include <disclaimer.h>;

Offline

#4 2006-07-17 23:30:09

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

Re: Odd behaviour using txp:php

In thinking about it, if txp:php is parsed as the page is processed, then it should appear where the tags are located in the page, shouldn’t it?

Textpattern relies on PHP output buffers to assemble its pages, and particularly to put <txp:php> output in the correct place. virtual() flushes the output buffers, so its behaviour is something Textpattern is just not designed to deal with.

If the cgi script merely produces HTML output, you could try include(‘http://example.com/path/to/tdp.cgi’). If it’s very simple, convert the CGI script to a Textpattern form or plugin.

If the cgi script processes POST data, you’ll need a more complex solution. Even if you find a way to use virtual(), it’s likely that the CGI environment variables won’t get passed to the script properly, particularly if you’re using clean URLs.


Alex

Offline

#5 2006-07-18 04:22:48

NyteOwl
Member
From: Nova Scotia, Canada
Registered: 2005-09-24
Posts: 539

Re: Odd behaviour using txp:php

I tried include firs with no success. Oh well, this is working fine. I may try translating it into PHP as a learning exercise, maybe from there to a plugin. It isn’t a very complicated script.


Obsolescence is just a lack of imagination. / 36-bits Forever! / #include <disclaimer.h>;

Offline

Board footer

Powered by FluxBB