i was programming a mail templatingsystem. The user should be able to use markers in there, they will be replaced by the actual data. The problem ist, my function to replace the markers works just fine, but i need to do a recursiv call of that function, that will only run once, and this is what i came up with:
public function replace_placeholders($content, $recipient, $settings, $interface, $recommendation, $format, $recursion = false) {
$content = $this->replace_ph('briefanrede' , $recipient['id'] , $content);
$content = $this->replace_ph('anrede' , $recipient['title'] , $content);
$content = $this->replace_ph('email' , $recipient['email'] , $content);
$content = $this->replace_ph('kundennummer' , $recipient['kdnumber'] , $content);
$content = $this->replace_ph('briefanrede' , $recipient['briefanrede'] , $content);
if($recipient['title'] == $settings['anrede_w'] || $recipient['title'] == $settings['anrede_m']) {
$content = $this->replace_ph('vorname' , $recipient['forename'] , $content);
$content = $this->replace_ph('nachname' , $recipient['surename'] , $content);
} else {
$content = $this->replace_ph('vorname' , "" , $content, true);
$content = $this->replace_ph('nachname' , "" , $content, true);
}
$content = $this->replace_salutation($recipient, $settings, $content);
//Recommendation
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) {
if($recommendation['own_page'] == 1) {
$baseurl = $recommendation['location'];
} else {
$baseurl = $recommendation['link'];
}
$pattern = ($format == "html") ? '%s' : '%s';
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
$content = $this->replace_ph('weiterempfehlung' , (($format == "html") ? sprintf($pattern, $url, $settings['text_weiterempfehlung']): sprinf($pattern, $url)), $content);
}
return $content;
}
The recursiv call in this line
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
is causing a 500 internal server error. I dont know why, because i think that i limited the recursion to run once. Can you help me out?
Sorry for my bad english i try hard to write clear sentences.
//EDIT:
Apache log:
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
[Wed May 30 15:31:56 2012] [error] [client xx.xxx.xx.xxx] File does not exist: /var/www/web80/html/web80-newsletter/favicon.ico
[Wed May 30 15:31:58 2012] [error] mod_fcgid: process /var/www/php-fcgi/web80.php53/php-fcgi(21975) exit(communication error), get unexpected signal 11
the php errorlog is empty.
It would seem you miss one argument in your recursive call, making the $recursive = false continue being false all the time, which in turn makes your if statement
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false)
always return true.
Try adding one last variable to your recursive call instead and you should be able to properly execute your script, ie:
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface,
$recommendation, true, true);
^ added one true
What i think you want to add instead of the first true is $format.
Signal 11 is SIGSEGV, i.e. the process crashed due to a bad memory access (such as dereferencing a NULL pointer or accessing memory it was not supposed to access).
This is nothing a PHP script should be causing, so you should first upgrade to the most recent stable PHP version and if it still happens reduce your script as much as possible (remove everything that can be removed while the crash still happens) and then report it as a PHP bug.
Related
I am writing this in shell;
sudo tail -100 /var/log/apache2/error.log
And, I saw this;
......
[Sun Feb 14 09:42:06.873076 2021] [php7:warn] [pid 1968] [client 82.222.237.83:36955] PHP Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/wp-includes/formatting.php on line 4314
[Sun Feb 14 09:42:06.873149 2021] [php7:warn] [pid 1968] [client 82.222.237.83:36955] PHP Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/wp-includes/formatting.php on line 4314
...
I'm going to the relevant code. --> /var/www/html/wp-includes/formatting.php on line 4314
function esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;
if ( '' === $url ) {
return $url;
}
$url = str_replace( ' ', '%20', ltrim( $url ) );
$url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%#$\|*\'()\[\]\\x80-\\xff]|i', '', $url );
if ( '' === $url ) {
return $url;
}
if ( 0 !== stripos( $url, 'mailto:' ) ) {
$strip = array( '%0d', '%0a', '%0D', '%0A' );
$url = _deep_replace( $strip, $url );
}
$url = str_replace( ';//', '://', $url );
on line 4314;
$url = str_replace( ' ', '%20', ltrim( $url ) );
I did not understand. My error page is full of this. I could not figure out despite my research. Can you help me?
Note: Ubuntu 20.04, Wordpress
Healthy days,
Best regards.
The function esc_url() is called with a $url that is object rather a string. You can use gettype() or print_r() to confirm. debug_backtrace() might be useful to figure out where you are making those calls from.
My code:
while ($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
$uri = 'https://www.themoviedb.org/movie/' . $row['tmdb_id'];
$get = file_get_contents($uri);
$pos1 = strpos($get, '<span class="genres">');
$pos2 = strpos($get, '</span>', $pos1);
$text = substr($get,$pos1,$pos2-$pos1+7);
if (strstr ($text, 'Animation'))
array_push ($array, $row['poster_path']);
}
it return me this error:
failed to open stream: HTTP request failed! HTTP/1.1 429 Too Many Requests
in "path/index.php" on line 128
line 128 is: $get = file_get_contents($uri);
Your target url is preventing this from happening. You're basically sending 70 requests in less than one second (probably). This is identified as an attack and at some point blocked.
You need to add some kind of timer to build some kind of queue that does this from time to time, instead of doing it all at once.
This is the error log, and i have no idea how to solve this.
[Thu Jan 25 10:39:42.689306 2018] [:error] [pid 21084]
PHP Warning: fgets(): SSL operation failed with code 1.
OpenSSL Error messages:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypterror:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypterror:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypterror:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt in ../vendor/pear-pear.horde.org/Horde_Imap_Client/Horde/Imap/Client/Socket/Connection/Socket.php on line 156
public function read($size = null)
{
$got_data = false;
$literal_len = null;
$token = new Horde_Imap_Client_Tokenize();
do {
if (feof($this->_stream)) {
$this->close();
$this->_params['debug']->info(
'ERROR: Server closed the connection.'
);
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Mail server closed the connection unexpectedly."),
Horde_Imap_Client_Exception::DISCONNECT
);
}
if (is_null($literal_len)) {
$buffer = '';
while (($in = fgets($this->_stream)) !== false) {
$got_data = true;
if (substr($in, -1) === "\n") {
$in = rtrim($in);
$this->_params['debug']->server($buffer . $in);
$token->add($in);
break;
}
$buffer .= $in;
$token->add($in);
}
/* Check for literal data. */
if (is_null($len = $token->getLiteralLength())) {
break;
}
// Skip 0-length literal data.
if ($len['length']) {
$binary = $len['binary'];
$literal_len = $len['length'];
}
continue;
}
$old_len = $literal_len;
while (($literal_len > 0) && !feof($this->_stream)) {
$in = fread($this->_stream, min($literal_len, 8192));
/* Only store in stream if this is something more than a
* nominal number of bytes. */
if ($old_len > 256) {
$token->addLiteralStream($in);
} else {
$token->add($in);
}
if (!empty($this->_params['debugliteral'])) {
$this->_params['debug']->raw($in);
}
$got_data = true;
$literal_len -= strlen($in);
}
$literal_len = null;
if (empty($this->_params['debugliteral'])) {
$this->_params['debug']->server('[' . ($binary ? 'BINARY' : 'LITERAL') . ' DATA: ' . $old_len . ' bytes]');
}
} while (true);
if (!$got_data) {
$this->_params['debug']->info('ERROR: read/timeout error.');
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Error when communicating with the mail server."),
Horde_Imap_Client_Exception::SERVER_READERROR
);
}
return $token;
}
The error appears at
while (($in = fgets($this->_stream)) !== false) {
I have another Instance of my application on the same server with the same settings just different database and domain name.
The other Instance seems to work just fine without having problems with this error.
Note: Horde is a kind of PHP library for sending Emails.
Can anyone help me?
Please try to change your setting as below:
<?php
$yourArrayOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
)
$response = file_get_contents("fileName", false,
stream_context_create($yourArrayOptions));
echo $response; ?>
please click here for better explanation file_get_contents(): SSL operation failed with code 1. And more
I am trying to build a log parser using the zLib functions, and am running into a problem. This is my code:
$filename = '/Users/awallace/AccessLogs/access.log.6.gz';
$handle = gzopen( $filename, 'r');
while ( $buffer = gzgets( $handle, 2048 ) )
{
if ( strpos($buffer, "Leadbuilder.") !== false )
{
print $buffer . "\n";
}
gzclose($handle);
}
(I have removed error checking code). WhenI run this, I get a warning:
Warning: gzgets(): 5 is not a valid stream resource in /Users/awallace/test.php on line 22
If I dump out the handle after gzopen, I get: "Resource id #5". Any idea why this isn't working?
PHP v:5.5.29
MacOS 10.10.5
Ouput of "file" command:
/Users/awallace/AccessLogs/access.log.6.gz: gzip compressed data, from
Unix, last modified: Wed Feb 24 23:35:20 2016
Thanks..
You close the handle inside your loop, so on the second loop iteration $handle is invalid.
Instead do this:
$handle = gzopen( $filename, 'r');
while ( !gzeof($handle) )
{
$buffer = gzgets( $handle, 2048 );
if ( strpos($buffer, "Leadbuilder.") !== false )
{
print $buffer . "\n";
}
}
gzclose($handle);
I'm having trouble using the facebook api to post a photo to a page's wall. If I upload the file via php and use $_FILES[]["tmp_name"] as my $filelocation it works fine. However if I change $filelocation to a local filepath ( /tmp/1351750505-24d.jpg ) it doesn't work.
I've given my /tmp dir 777 and made sure my file is 777 as well to eliminate any permission issues. I've also used multiple files to make sure its not just an issue with one file.
The only other thought I have is that this could be a random setting in php.ini, but I didn't see anything glaring at me.
Error log:
[Thu Nov 01 06:52:13 2012] [error] [client 66.x.x.x] {"error":{"message":"(#1) An unknown error occurred","type":"OAuthException","code":1}}, referer: http://origin.example.com/adder/index.php
[Thu Nov 01 06:52:13 2012] [error] [client 66.x.x.x] $filelocation = /tmp/1351752730-24e.jpg, referer: http://origin.example.com/adder/index.php
[ec2-user#ip-10-x-x-x adder]$ ll /tmp/1351750505-24d.jpg
-rwxrwxrwx 1 apache apache 331 Nov 1 06:15 /tmp/1351750505-24d.jpg
$facebook->setFileUploadSupport(true);
$post_id = "";
try
{
$post_id = $facebook->api("/$page_id/photos", 'POST',
array(
'source' => '#' . $filelocation,
'message' => $name
));
error_log("\$filelocation = " . $filelocation);
} catch (FacebookApiException $e)
{
$result = $e->getResult();
error_log(json_encode($result));
$post_id["id"] = "FAIL!";
error_log("\$filelocation = " . $filelocation);
}
When I set $filelocation to /tmp/somefile.jpg it posts the local path/file fine. I notice one difference between your code and my code: I include the page access token in the POST call:
$local_path = '/tmp/water96x96.jpg';
$args = array(
'access_token' => $page_info['access_token'],
'message' => 'Testing photo upload via SDK!',
'source' => '#'.$local_path,
);
$post_id = $facebook->api('/'.$page_id.'/photos', 'post', $args);
To get the page access token, I do:
$page_info = $facebook->api('/'.$page_id.'?fields=access_token');
with a logged in user who is an admin of the page with manage_pages permission.