PHP/Joomla "Premature end of script headers: cgi_wrapper" - php

I'm experiencing a 500, Internal Server error on my website. The error logs show the following error: "Premature end of script headers: cgi_wrapper", in my Joomla application.
It only occurs when one particular file is loaded. The rest of the application/website works as it should. There are no other related issues that show up in the error logs - no indication of a timeout or a permissions error.
The file that is causing the error is a template/layout file. Furthermore, I have identified a snippet of code that will cause the error, when this is commented out, the site loads just fine. Here it is:
if( $question->type == '1' || $question->type == '2' || $question->type == '3' )
{
//shuffle items
$shuffled_items = $this->shuffle_assoc($items);
$output = '';
$output .= '<table class="answer-table">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<ul class="answers">';
foreach($shuffled_items as $item)
{
$output .= '<li num=' . $item->num . '>';
$output .= $item->item;
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</td>';
$output .= '</tr>';
$output .= '</table>';
$output .= '<table class="answer-table correct-answer" style="display: none">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<p class="question-instructions">Correct Answer:</p>';
$output .= '<ul class="answers correct-answer">';
foreach($items as $item)
{
$output .= '<li num=' . $item->num . '>';
$output .= $item->item;
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</td>';
$output .= '</table>';
echo $output;
}
It uses a variable, $questions, that is set in the view.html.php file (for those who know Joomla). It is this variable that seems to be triggering the error. If I don't assign the $questions variable, then the template will load just fine.
Also, in the example above, it first tests the question type ($question->type). There are other sections of code that would be triggered, and still produce the error, if $question->type is not 1, 2, or 3. But I left out the other code for brevity, and because it only gets called when the relevant question type exists. When the code above alone gets run, it causes the error.
So, I'm lost here. What baffles me is that only this template file, and the $questions variable causes the error. Everything else works fine. It also runs fine on my local server.
Almost forgot, using Joomla 1.5.22, PHP 5.3.3, Apache 2.2.3, Cent OS 5.8. The server also runs Parallels Plesk Panel 10.
I hope someone can point me to a solution.
Thanks!

Check /var/log/httpd/suexec_log
and permissions on /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
it should be
ls -la /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
-rwxr-xr-x 1 root root 5288 Jul 14 2011 /var/www/cgi-bin/cgi_wrapper/cgi_wrapper

Related

How to add a link to a list in php

Hi I have a Api list that is been generated using php here is the code that is been used to generate the list
<html>
<title> API LIST</title>
<body>
<?php
$jsondata = file_get_contents("api_link");
$json = json_decode($jsondata, true);
$output = "<ul>";
foreach($output['A'] as $schools){
$output .= "<li>".$schools['name']."</li>";
}
$output .="</ul>";
echo $output;
?>
the list is populated successfully but how can i add a link to the list so that when a user click on one of the items it opens a particular linked page here are the ways i have tried
$output .= "<li ".$schools['name']."</li>";
$output .= "<li>".$schools['name']. "</li>";
$output .= "<li>".$schools['name']."</li>";
I don't know where or how to add the a href code
Use
$output .= '<li>'.$schools['name'].'</li>';
You just need some changes in your code.You can try for
$output .= '<a href=https://www.google.com'.$schools['name'].'><li>'.$schools['name'].'</li></a>';
As per the comments you can use . to concatenate(join) the string and variable in php.

Link opens as part of page PHP

I have problem with simple link function. On submission form, there is textbox where user can include url. This url is then taken and changed into working link and placed in post. This part works fine. If user include http/https in front of url it will work fine. But if they don't include http/https or only www, then it will open link as example below:
mysiteexample.com/UrlTheyPasted.com
mysiteexample.com/www.UrlTheyPasted.com
(This should open as link to Video/Image/Site,..)
Here is code:
$output .= '<DIV CLASS="'.$outerclass.'">';
$output .= '<DIV CLASS="'.$innertclass.'">'.$title.'</DIV>';
$output .= '<DIV CLASS="'.$innervclass.'">'.$value.'</DIV>';
$output .= '</DIV>';
Anyone know solution for this or why is this happening?
During the processing of the user input, use parse_url() to find out if they have put the protocol on or not and act accordingly.
$url = 'test.com';
$urlscheme = parse_url($url, PHP_URL_SCHEME);
if (empty($urlscheme)) {
$url = 'http://'.$url;
}
die('<pre>'.print_r($url,true));
so for instance, just before your code, put the example:
$scheme = parse_url($value, PHP_URL_SCHEME);
if (empty($scheme)) $value = 'http://'.$value;
$output .= '<DIV CLASS="'.$outerclass.'">';
$output .= '<DIV CLASS="'.$innertclass.'">'.$title.'</DIV>';
$output .= '<DIV CLASS="'.$innervclass.'">'.$value.'</DIV>';
$output .= '</DIV>';

How to submit an ajax call from joomla plugin

I have a challenge that is bugging me.
The thing is - I'm creating a plugin that is doing an AJAX call to another file in this plugin. It seems Joomla is preventing me from accessing that file.
I need to POST to a file that returns data from a SOAP call.
I'm calling the file from this line:
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
I've tried both a relative, absolute and server path as well - Joomla doesn't like it. But I can't remember or find the correct way to do it.
The file is in the same folder as the plugin that outputs above code.
Here's the complete javascript function my plugin outputs:
$html .= '<script type="text/javascript">';
$html .= 'function searchParcels()';
$html .= '{';
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
$html .= 'function(data) {';
$html .= 'var shops = $.parseJSON(data);';
$html .= '$(\'#shops_output\').html(\'\');';
$html .= 'for(i in shops)';
$html .= '{';
$html .= 'var html = \'<p>\'';
$html .= '+ shops[i][\'CompanyName\'] + \'<br>\'';
$html .= '+ shops[i][\'Streetname\'] + \'<br>\'';
$html .= '+ shops[i][\'ZipCode\'] + \' \' + shops[i][\'CityName\'] + \'<br>\'';
$html .= '+ shops[i][\'Telephone\'] + \'<br>\'';
$html .= '+ \'</p>\';';
$html .= '$(\'#shops_output\').append(html);';
$html .= '}';
$html .= '});';
$html .= '}';
$html .= '</script>';
Any help is greatly appreciated :-)
Thanks.
Please check this post on how to use Joomla's ajax interface (it seems you are not using it). This is much easier and much cleaner (and much more standard) than the method you described. All you need to do is to create the module/plugin (make sure that you have a function name ending with "Ajax") and then issue the right call from anywhere on your Joomla website (make sure you use the URL pattern described on the website).

PHP Wkhtmltopdf will not generate more than 41 pages

I am generating a file with data represented in a html table. The problem occurs when there is so much data that wkhtmltopdf would need to generate page number 42. It never finishes loading. If there is lets say 5000 elements and that covers exactly 41 pages it'll generate quickly, but if I add another element it wont finish.
I am using a php wrapper. There is not a lot of code...
This is the function that builds the html
private function _generate() {
$_html .= '<table>';
$_html .= '<tr>';
$_html .= '<th>Naziv medija</th>';
$_html .= '</tr>';
foreach ($this->_model as $value) {
$_html .= '<tr>';
$_html .= '<td>' . $value->attributes['naziv'] . '</td>';
$_html .= '</tr>';
}
$_html .= '</table>';
return $_html;
}
This function then returns the html to the bottom code
$pdf = new WKPDF();
$pdf->set_html($this->_generate());
$pdf->set_orientation($orientation);
$pdf->set_page_size($pagesize);
$pdf->render();
$pdf->output($type, $this->_filename);
If I generate the html and save it somewhere and then create the pdf through the console there is no problem, it works fine.
Any ideas why i cannot generate more than 41 pages with php?

Cat + Tag Filter Plugin for WordPress: Checkboxes not being saved

I'm using the Cat + Tag Filter Plugin for WordPress and it works fine except that the checkboxes that are supposed to be saved between tag searches are not being saved. All but the last one selected is being cleared, leading me to suspect that there is something wrong in the foreach statement that displays each checkbox and checks to see if that tag was included in the tag array.
My question is, how can I keep the tag checkboxes checked and not just the last one and is there anything wrong with this foreach statement?
if ($type == 1){
if ($there_are_tags){
$options .= '<ul>';
foreach ($tags as $tag) {
$options .= '<li>';
$options .= '<input type="checkbox" name="';
$options .= "tag[]";
$options .= '" value="' . $tag->slug . '"';
if (is_array($current_tax['tags'])) {
if (in_array($tag->slug, $current_tax['tags'])) {
$options .= ' checked ';
}
}
$options .= '>';
$options .= $tag->name;
if ($ctf_options['tags_count'] == 1) $options .= ' (' . $tag->count . ')';
$options .= '</li>';
}
$options .= '</ul>';
}
else $options .= '<ul><li><input type="checkbox" name="tag[]" value="-1" disabled>' . __('No tags here', 'cat-tag-filter') . '</li></ul>';
}
Unfortunately, there is a well documented list of issues with this plugin and not a very good response rate from the plugins creators. Some posts recent about the plugin are saying that it doesn't work at all with Wordpress 3.6. Your options are some what limited, you can put a bounty on the issues and try and attract some to do a custom fix on the issues for the plugin, you can hold out for a plugin update or you can try implementing something like Isoptope for Wordpress (this has a bit learning curve to use).
Lastly, I just found that if you have the Yoast or Pretty Permalinks plugins installed there are documented conflicts with these plug-ins and Cat+Tags filter so you could try turn some of your plugins on and off to see if this fixes the issue for you.
I hope this helps some.

Categories