HTML2PDF Not work in hosting, but work in localhost - php

This my error:
Strict Standards: Declaration of FPDF_Alpha::Image() should be compatible with FPDF::Image($file, $x = NULL, $y = NULL, $w = 0, $h = 0, $type= '', $link = '') in /home/stekomin/public_html/ujian/html2pdf_v3.31/_mypdf/03_fpdf_alpha.class.php on line 21
Warning: Cannot modify header information - headers already sent by (output started at /home/stekomin/public_html/ujian/html2pdf_v3.31/_mypdf/03_fpdf_alpha.class.php: 21) in /home/stekomin/public_html/ujian/html2pdf_v3.31/_mypdf/03_fpdf_alpha.class.php on line 1017
FPDF error: Some data has already been output, can't send PDF file

You should disable to show errors on your production server:
ini_set('display_errors', '0');
error_reporting(E_ALL | E_STRICT);
The first line disables showing the errors to the user, the second line though enables the logging of these errors.
Cannot modify header information - headers already sent by ...
This error occurs because there is already content sent to the user ( your error message ) and FPDF wants to set header information, which must happen before content is sent.

Related

Found this error when I opened my Wordpress panel

Found this error when I opened my Wordpress panel:
Warning: Invalid argument supplied for foreach() in /home/cactusbo/domains/cactusbook.com/public_html/wp-content/plugins/jet-engine/framework/jet-dashboard/inc/plugin-manager.php on line 148
Warning: Invalid argument supplied for foreach() in /home/cactusbo/domains/cactusbook.com/public_html/wp-content/plugins/jet-engine/framework/jet-dashboard/inc/plugin-manager.php on line 148
Warning: Cannot modify header information - headers already sent by (output started at /home/cactusbo/domains/cactusbook.com/public_html/wp-content/plugins/jet-engine/framework/jet-dashboard/inc/plugin-manager.php:148) in /home/cactusbo/domains/cactusbook.com/public_html/wp-admin/includes/misc.php on line 1416
Warning: Cannot modify header information - headers already sent by (output started at /home/cactusbo/domains/cactusbook.com/public_html/wp-content/plugins/jet-engine/framework/jet-dashboard/inc/plugin-manager.php:148) in /home/cactusbo/domains/cactusbook.com/public_html/wp-includes/functions.php on line 6865
Warning: Cannot modify header information - headers already sent by (output started at /home/cactusbo/domains/cactusbook.com/public_html/wp-content/plugins/jet-engine/framework/jet-dashboard/inc/plugin-manager.php:148) in /home/cactusbo/domains/cactusbook.com/public_html/wp-admin/admin-header.php on line 9
foreach ( $this->registered_plugins_data as $plugin_file => $plugin_data ) {
if ( $plugin_data['slug'] === $_args->slug ) {
$registered_plugin_data = $plugin_data;
break;
}
}
I searched but could not find any answer directly to my error. and I do not know a lot about php.

php mail error handling when no smtp server

I make a php page to send email. I will give this page to multiple users, but I have no control of the server they will use. And some of them should have no SMTP server. So I try to handle this error.
For example, on my own computer, if I deactivate my SMTP server, I receive a "PHP Warning: mail(): Failed to connect to mailserver at ..." error message.
My code :
try
{
$okmail=mail($to,$Subject,$texte,$headers);
}
catch (Exception $ex)
{
...
}
But this code doesn't throw an exception, it only write the error message (like an "echo(...)" statement).
I use this code in a xmlhttprequest page and use an xml type response. But the original page receive the error message before the xml text :
PHP Warning: mail(): Failed to connect to mailserver at ... \n1Email not send
How can I handle this "no SMTP" error ?
Thanks!
If I understand the problem correctly, the following directive will hide the warnings.
ini_set('display_errors', 0);
Instead of "try/catch" you can use the following approach.
set_error_handler("warningHandler", E_USER_WARNING);
// Trigger some warning here for testing purposes only (this is just an example).
trigger_error('This here is the message from some warning ...', E_USER_WARNING);
// If you need DNS Resource Records associated with a hostname.
// $result = dns_get_record($_SERVER['HTTP_HOST']);
// Restores the previous error handler function.
restore_error_handler();
// This is your custom warning handler.
function warningHandler($errno, $errstr) {
// Do what you want here ...
echo $errno, ' ::: ', $errstr;
}
Thanks for your answers, but nothing works :(
I find a solution by cleaning the output buffer by using ob_start(null,0,PHP_OUTPUT_HANDLER_CLEANABLE) and ob_clean() just after the mail() function.
I don't understand why the mail function writes an error into the output buffer

PHP Fatal error: Call to undefined method JDocumentError::close()

I've searched for a solution everywhere but I couldn't find an answer. Some days I got this error without change or do anything:
And I can't access my website in the entire day but suddenly starts working again without any change, and some days later the same problem. What can I do?
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at
webmaster#magic.kiwitextil.com to inform them of the time this error
occurred, and the actions you performed just before this error.
More information about this error may be available in the server error
log.
Additionally, a 500 Internal Server Error error was encountered while
trying to use an ErrorDocument to handle the request.
My site is: www.magic.cr
I can access to the backend always! (magic.cr/administrator)
I've checked my server logs and I got this lines repeating constantly:
[23-Aug-2016 16:44:53 UTC] PHP Deprecated: Non-static method
JApplication::redirect() should not be called statically, assuming
$this from incompatible context in
/home/kiwitex/public_html/magic.cr/templates/braink/error.php on line
9
[23-Aug-2016 16:44:53 UTC] PHP Notice: Undefined property:
JDocumentError::$_messageQueue in
/home/kiwitex/public_html/magic.cr/libraries/legacy/application/application.php
on line 376
[23-Aug-2016 16:44:53 UTC] PHP Notice: Undefined property:
JDocumentError::$client in
/home/kiwitex/public_html/magic.cr/libraries/legacy/application/application.php
on line 394
[23-Aug-2016 16:44:53 UTC] PHP Notice: Trying to get
property of non-object in
/home/kiwitex/public_html/magic.cr/libraries/legacy/application/application.php
on line 394
[23-Aug-2016 16:44:53 UTC] PHP Fatal error: Call to
undefined method JDocumentError::close() in
/home/kiwitex/public_html/magic.cr/libraries/legacy/application/application.php
on line 409
/home/kiwitex/public_html/magic.cr/libraries/legacy/application/application.php
Lines 376 to 409
if (count($this->_messageQueue))
{
$session = JFactory::getSession();
$session->set('application.queue', $this->_messageQueue);
}
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
}
else
{
$document = JFactory::getDocument();
jimport('phputf8.utils.ascii');
if (($this->client->engine == JApplicationWebClient::TRIDENT) && !utf8_is_ascii($url))
{
// MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />'
. '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script></head></html>';
}
else
{
// All other browsers, use the more efficient HTTP header method
header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
header('Location: ' . $url);
header('Content-Type: text/html; charset=' . $document->getCharset());
}
}
$this->close();
/home/kiwitex/public_html/magic.cr/templates/braink/error.php
Lines 8 to 10
case "404":
JApplication::redirect("index.php/404-error"); // replace the redirect URL with your own
break;
Please help I cannot access my site in the last 36 hours!!!

WP REST API query multiple post types

I am trying to retrieve posts from multiple post types using WP REST API. I have no problem getting a feed from one post type book by doing this:
http://example.com/wp-json/posts?type=book&filter[posts_per_page]=10
Now I want to extend the feed to get book and movie. This only gives me the last specified type:
http://example.com/wp-json/posts?type=book&type=movie&filter[posts_per_page]=10
This gives me an error:
http://example.com/wp-json/posts?type[]=book&type[]=movie&filter[posts_per_page]=10
How should I be handling this?
Thanks!
Edit: Fixed syntax to match what I actually have. Here are the errors that I get when this syntax http://example.com/wp-json/posts?type[]=book&type[]=movie&filter[posts_per_page]=10 is used:
Warning: urlencode() expects parameter 1 to be string, array given in /home/newbreak/public_html/wp-includes/formatting.php on line 4128
Warning: Cannot modify header information - headers already sent by (output started at /home/newbreak/public_html/wp-includes/formatting.php:4128) in /home/newbreak/public_html/wp-content/plugins/json-rest-api/lib/class-wp-json-server.php on line 587
Warning: Cannot modify header information - headers already sent by (output started at /home/newbreak/public_html/wp-includes/formatting.php:4128) in /home/newbreak/public_html/wp-content/plugins/json-rest-api/lib/class-wp-json-server.php on line 587
Warning: Cannot modify header information - headers already sent by (output started at /home/newbreak/public_html/wp-includes/formatting.php:4128) in /home/newbreak/public_html/wp-content/plugins/json-rest-api/lib/class-wp-json-server.php on line 587
Warning: Cannot modify header information - headers already sent by (output started at /home/newbreak/public_html/wp-includes/formatting.php:4128) in /home/newbreak/public_html/wp-content/plugins/json-rest-api/lib/class-wp-json-server.php on line 587
Warning: Cannot modify header information - headers already sent by (output started at /home/newbreak/public_html/wp-includes/formatting.php:4128) in /home/newbreak/public_html/wp-content/plugins/json-rest-api/lib/class-wp-json-server.php on line 587
Warning: Cannot modify header information - headers already sent by (output started at /home/newbreak/public_html/wp-includes/formatting.php:4128) in /home/newbreak/public_html/wp-content/plugins/json-rest-api/lib/class-wp-json-server.php on line 587
I only get the errors when I send the type as an array type[].
You can also try registering an additional endpoint so you don't have to add as many query arguments in each request. I'm using the latest version of the WP REST API plugin.
So for a custom content type called "movies", you could have an endpoint like wp-json/wp/v2/movies
add_action('rest_api_init', 'register_movies');
function register_movies() {
$movies_custom_fields = array(
'director',
'genre'
);
foreach ($movies_custom_fields as $key) {
register_rest_field('movies', $key, array(
'schema' => null,
'get_callback' => 'get_movies_data',
));
}
}
function get_movies_data( $object, $field_name, $request ) {
return get_post_meta( $object[ 'id' ], $field_name, true );
}
More documentation on adding custom endpoints for different content types at the WP REST API V2 documentation site.
We had a similar requirement, where we only had a slug and need to query / find the post/page/article data.
We have build a wordpress api v2 plugin to query multiple post types.
Here is the plugin code https://github.com/elevati/wp-api-multiple-posttype

PHP fatal error: Uncaught exception 'Exception' with message

I have a PHP script that connects to an api and posts information to their systems, but when its trying to connect it throws a fatal error:
Fatal error: Uncaught exception 'Exception' with message 'Problem with
'http://apitestserver.co.uk:9000/Service.svc/Items' in
/var/www/html/e/connect_test.php:17 Stack trace: #0
/var/www/html/e/connect_test.php(39):
do_http_request('http://apitest....', 'hello') #1 {main} thrown in
/var/www/html/e/connect_test.php on line 17
If I send it to a PHP script which just grabs the IP then it works, but if I send it to the API it doesn't. My PHP script creates XML and then forwards to the server. I was getting errors so I just created the following smaller script purely to test the connection:
function do_http_request($url, $data, $method = 'POST',
$optional_headers = 'Content-Type: application/atom+xml') {
$params = array(
'http' => array(
'method' => $method,
'content' => $data
)
);
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url");
}
$response = #stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url");
}
$metaData = stream_get_meta_data($fp);
fclose($fp);
if(!preg_match('~^HTTP.*([0-9]{3})~',
$metaData['wrapper_data'][0], $matches)){
throw new Exception('MALFORED RESPONSE - COULD NOT UNDERSTAND HTTP CODE');
}
if (substr($matches[1], 0, 1) != '2') {
throw new Exception('SERVER REPORTED HTTP ERROR ' . $matches[1]);
}
return $response;
}
$data = 'hello';
$paul =
do_http_request('http://apitestserver.co.uk:9000/Service.svc/Items',$data);
echo $paul;
If I change the URL to a simple script on another one of our servers which just grabs the IP of the incoming connection and returns it:
$ip=$_SERVER['REMOTE_ADDR'];
echo 'IP equals = ' . $ip;
Then it works fine with no errors.
Update -
with errors on it throws the following warning, probably because the script is not sending the correct info to the API
Warning: fopen(http://apitestserver.co.uk:9000/Service.svc/Items)
[function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1
500 Data at the root level is invalid. Line 1, position 1.
Also note that I can access the api server fine using fiddler to send manually created items across, its just when this script tries to connect and send data there is an issue. I wrote another quick script which connects and prints out the default response (an rss feed of submitted items)
When I run the 'main' connector script it throws the following two errors
Warning: fopen() [function.fopen]: php_network_getaddresses:
getaddrinfo failed: Name or service not known in
/var/www/html/e/sequence.php on line 65
Warning: fopen(http://apitestserver.co.uk:9000/Service.svc/Items)
[function.fopen]: failed to open stream: Operation now in progress
in /var/www/html/e/sequence.php on line 65
I would suggest using curl instead of fopen(). curl is both more flexible, and more secure. Many servers disable allow_url_fopen, curl also fails more gracefully when there are problems on the remote server.
I just tested the URL in my browser and got a connection error.
Maybe the problem is with their server (or you have the wrong URL)?
Edit:
Looks like ther server is throwing a 500 error - maybe because the data you're posting is invalid.
You could use a packet sniffer and check the exact data you're sending to the server (or use cURL as suggested by #acrosman)
apitestserver.co.uk doesn't respond to ping and the url is inaccessable. The API-server doesn't seem to be up.
or You can change the headers:
$optional_headers = 'Content-Type: application/json')
First error message suggests problems with apitestserver - it returns error code 500, which states for "Internal server error".
Second one informs that PHP can't resolve host name into IP address - I'd look into DNS configuration and/or hosts file.
Apparently 'fopen' function does not return proper stream. There can be many possibilities when that happens, but according to PHP manual, fopen function on fail should present E_WARNING message with proper commentary. It is possible that you have errors of that class silenced - call error_reporting(E_ALL) at the beginning of your script and look for some relevant error messages.

Categories