Order API PHP Script ContentType problem

General ShopSite user discussion

Order API PHP Script ContentType problem

Postby shdanfo » Tue Aug 04, 2009 12:40 pm

I'm trying to write an Order API script using PHP, but can't seem to set the content type as text/html in a way that is supported when the script is run by ShopSite. So, the HTML output from the script is displayed to the customer as text with all the tags, instead of being formated as desired. My ShopSite service (Lexiconn) explained the solution: Use a perl script to output the ContentType line, and then the rest of the output can come from the php script.

It works, but what a HACK! I can't beleve that ShopSite doesn't support PHP Order API scripts that return html unless perl is used as an initial script to set the content type.

Is it possible that there's something wrong with Lexiconn's set up? :?:
shdanfo
 
Posts: 3
Joined: Tue Aug 04, 2009 12:25 pm

Postby loren_d_c » Tue Aug 04, 2009 1:17 pm

You can use PHP scripts directly (you will need to have a CLI-enabled version of PHP) for the Order API and Custom Shipping Add-on. See the following threads from this very forum regarding using PHP for these api's:

http://support.shopsite.com/forums/viewtopic.php?t=6283
http://support.shopsite.com/forums/viewtopic.php?t=2028
http://support.shopsite.com/forums/viewtopic.php?t=2173
http://support.shopsite.com/forums/viewtopic.php?t=2105
http://support.shopsite.com/forums/viewtopic.php?t=2499

And:

http://www.php.net/manual/en/features.commandline.php

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Still No ContentType Solution

Postby shdanfo » Tue Aug 04, 2009 1:54 pm

I'm not having any problems invoking or executing a PHP script from Order API. The problem is that I want to provide HTML output to the customer and this isn't working. The output seen by the customer contains all the output I print, exactly as I print it, including HTML formating tags. The output is NOT displayed as formated HTML.

I appreciate all of the links to forum entries that were provided in the previous post, but none of these entries show (or indicate success with) HTML output from a PHP Order API script.

I've tried header('Content-type: text/html');
and have tried print "Content-type: text/html\n\n";

Neither one works. Only by running two scripts in sequence, the first of which is written in perl to print "Content-type: text/html\n\n"; am I able to output HTML text from a second script written in PHP and have the result appear to a customer as formated HTML (with clickable links).
shdanfo
 
Posts: 3
Joined: Tue Aug 04, 2009 12:25 pm

Postby loren_d_c » Tue Aug 04, 2009 2:34 pm

The following simple PHP script works fine for me with the Order API:

Code: Select all
#!/usr/bin/php -q
<?php
$query_string = trim(fgets(STDIN));
parse_str($query_string,$params);

echo "Content-type: text/html\n\n";
?>

<head>
<title>Test</title>
</head>
<body>This is a test!</body>


Of course, I already know that the PHP binary on my server is a CLI-enabled binary.

Also note that if I leave a space between the interpreter line and the opening <?php tag then I get the same results as you. This is because PHP interprets all text, including whitespace, outside of the PHP tags as text so it is outputting default text headers for this blank line before your code is printing out the HTML content-type, and the first content-type that is output wins. So do you have any spaces outside of PHP tags and before your own HTML content-type in your code?

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Yes!!!

Postby shdanfo » Tue Aug 04, 2009 2:48 pm

Yes, I have a blank line between the interpreter line and the opening php tag.

Yes, Yes, Yes. Thank you Thank you Thank you!!!!

:D :D :D
shdanfo
 
Posts: 3
Joined: Tue Aug 04, 2009 12:25 pm


Return to User Forum

Who is online

Users browsing this forum: No registered users and 131 guests