Zend Framework 2 Zend_Http_Client SSL Connection Error - zend-framework

i want to parse all kinds of ssl/https Sites.
E.g i want the content of https://microsoft.de, but it do not work. Following Erros appears:
Fatal error: Uncaught exception 'ErrorException' with message 'stream_socket_enable_crypto() [<a href='function.stream-socket-enable-crypto'>function.stream-socket-enable-crypto</a>]:
SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed'
in C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php:276
Stack trace: #0 [internal function]: Zend\Stdlib\ErrorHandler::addError(2, 'stream_socket_e...', 'C:\Users\Privat...', 276, Array) #1 C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php(276): stream_socket_enable_crypto(Resource id #35, true, 2)
#2 C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client.php(1356): Zend\Http\Client\Adapter\Socket->connect('microsoft.de', 443, true) #3 C:\Users\Privat\Desktop\Server\Apache2\htdocs\ in C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php on line 299
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Socket',
'ssltransport' => 'tls'
);
$client = new \Zend\Http\Client("https://microsoft.de");

You can tell the client not to verify the SSL, try this config:
$clientConfig = array(
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE
),
);
$this->_client = new \Zend\Http\Client('https://microsoft.de', $clientConfig);

Related

How to fix this error in Slim framework?

I installed Slim framwork using composer in wamp server.
But displays following error.
I am new to Slim.
Slim Application Error
The application could not run because of the following error:
Details
Type: ErrorException Code: 2 Message:
file_get_contents(templates/index.html): failed to open stream: No
such file or directory File:
D:\wamp\www\photometa\vendor\twig\twig\lib\Twig\Loader\Filesystem.php
Line: 131 Trace
0 [internal function]: Slim\Slim::handleErrors(2, 'file_get_conten...', 'D:\wamp\www\pho...', 131, Array)
1 D:\wamp\www\photometa\vendor\twig\twig\lib\Twig\Loader\Filesystem.php(131):
file_get_contents('templates/index...')
2 D:\wamp\www\photometa\vendor\twig\twig\lib\Twig\Environment.php(397):
Twig_Loader_Filesystem->getSource('index.html')
3 D:\wamp\www\photometa\vendor\slim\views\Twig.php(87): Twig_Environment->loadTemplate('index.html')
4 D:\wamp\www\photometa\vendor\slim\slim\Slim\View.php(255): Slim\Views\Twig->render('index.html', NULL)
5 D:\wamp\www\photometa\vendor\slim\slim\Slim\View.php(243): Slim\View->fetch('index.html', NULL)
6 D:\wamp\www\photometa\vendor\slim\slim\Slim\Slim.php(757): Slim\View->display('index.html')
7 D:\wamp\www\photometa\public\index.php(33): Slim\Slim->render('index.html')
8 [internal function]: {closure}()
9 D:\wamp\www\photometa\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)
10 D:\wamp\www\photometa\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch()
11 D:\wamp\www\photometa\vendor\slim\slim\Slim\Middleware\Flash.php(85):
Slim\Slim->call()
12 D:\wamp\www\photometa\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92):
Slim\Middleware\Flash->call()
13 D:\wamp\www\photometa\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67):
Slim\Middleware\MethodOverride->call()
14 D:\wamp\www\photometa\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()
15 D:\wamp\www\photometa\public\index.php(37): Slim\Slim->run()
16 {main}
This is index.php
<?php
require '../vendor/autoload.php';
// Prepare app
$app = new \Slim\Slim(array(
'templates.path' => '../templates',
));
// Create monolog logger and store logger in container as singleton
// (Singleton resources retrieve the same log resource definition each time)
$app->container->singleton('log', function () {
$log = new \Monolog\Logger('slim-skeleton');
$log->pushHandler(new \Monolog\Handler\StreamHandler('../logs/app.log', \Monolog\Logger::DEBUG));
return $log;
});
// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array(
'charset' => 'utf-8',
'cache' => realpath('../templates/cache'),
'auto_reload' => true,
'strict_variables' => false,
'autoescape' => true
);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
// Define routes
$app->get('/', function () use ($app) {
// Sample log message
$app->log->info("Slim-Skeleton '/' route");
// Render index view
$app->render('index.html');
});
// Run app
$app->run();
Try this :
$app = new \Slim\Slim(array(
'templates.path' => __DIR__ . '/../templates/',
));

Codeigniter A PHP Error was encountered, Filename: mysqli/mysqli_driver.php

I am using Codeigniter 3.0.0 and have just tested the program live online. The website is www.theloven.com.
The problem is like below
I could not fix the error.I need some help on this case
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (42000/1203): User ... already has more than 'max_user_connections' active connections
Filename: mysqli/mysqli_driver.php
Line Number: 135
Backtrace:
File: /home/.../public_html/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/theloven8/public_html/system/core/Exceptions.php:272)
Filename: Session/Session.php
Line Number: 140
Backtrace:
File: /home/.../public_html/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/theloven8/public_html/system/core/Exceptions.php:272)
Filename: Session/Session.php
Line Number: 168
Backtrace:
File: /home/.../public_html/index.php
Line: 292
Function: require_once
First you have specify local host user name and passwords in config > database.php
'hostname' => 'localhost',
'username' => 'uname',
'password' => 'password',
'database' => 'project',
'dbdriver' => 'mysqli',

Facebook PHP SDK "couldn't connect to host"

I'm trying to connect to facebook API
require_once '/composer/vendor/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'xxxx', // obviously, I've put my app ID in here
'app_secret' => 'xxxx', // and my app secret in here
'default_graph_version' => 'v2.4',
]);
To do the following request, which, if I'm right, should give me the number of shares of the URL :
$target = 'http://stackoverflow.com';
$node = $fb->get('/?id='.urlencode($target).'&fields=share')->getGraphNode();
$shareCount = $node['share']['share_count'];
However, I get the following error :
Fatal error:
Uncaught exception 'Facebook\Exceptions\FacebookSDKException'
with message 'couldn't connect to host'
in /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php:83
Stack trace:
#0 /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/FacebookClient.php(216):
Facebook\HttpClients\FacebookCurlHttpClient->send('https://graph.f...', 'GET', '', Array, 60)
#1 /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(504):
Facebook\FacebookClient->sendRequest(Object(Facebook\FacebookRequest))
#2 /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(377):
Facebook\Facebook->sendRequest('GET', '/?id=http%3A%2F...', Array, NULL, NULL, NULL)
#3 /backend/the_script_i_am_currently_trying_to_run.php(79):
Facebook\Facebook->get('/?id=http%3A%2F...')
#4 {main} thrown in /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php on line 83
From what I have read, it could be that I'm not allowed to use cURL on my server, but I'm using it somewhere else and it works, so I don't think the problem comes from here.
Any idea of what I'm doing wrong ?
Thanks

mblox soap api - php soap Payment Request not working

mblox soap api - php soap Payment Request not working and gives error.
I use as below code in subscribe.php file...
$client = new SoapClient("https://ngp.us.mblox.com/client-gateway/services?wsdl", array('trace' => 1, 'encoding' => 'UTF-8', 'soap_version' => SOAP_1_2));
$array = array(
'SecurityContext'=>array('userId'=>'aaaaaaaa','password'=>'bbbbbbbb'),
'ClientDetails'=>array('shortcode'=>'234242', 'brandName'=>'aaaaaaaaaa.com', 'programSponsor'=>'aaaaaaaaaa', 'originatingUrl'=>'www.aaaaaaaaaa.com', 'minPageUrl'=>'www.aaaaaaaaaa.com', 'successUrl'=>'www.aaaaaaaaaa.com/subscribConfirm.php', 'cancelUrl'=>'www.aaaaaaaaaa.com', 'tcUrl'=>'www.aaaaaaaaaa.com/terms.html', 'postBackUrl'=>'http://aaaaaaaaaa/subscribe.php'),
'paymentDetails'=>array('paymentType'=>'PSMS', 'amount'=>'9.99', 'currency'=>'USD', 'billingFrequency'=>'MONTHLY'),
'msisdn'=>'243233232',
'serviceId'=>'332',
'operatorId'=>'33343',
'productDescription'=>'Text test',
'optInBody'=>'aaaaaaaaaa',
'browserSessionId'=>'123456',
);
$result = $client->initiatePayment($array);
It shows error as below on last line => $result = $client->initiatePayment($array);
Fatal error: Uncaught SoapFault exception: [(null)] in
/aaaaaaaa/Source/developement/PHP/ver1/subscribe.php:97 Stack trace:
0 /aaaaaaaa/Source/developement/PHP/ver1/subscribe.php(97): SoapClient->__call('initiatePayment', Array) #1
/aaaaaaaa/Source/developement/PHP/ver1/subscribe.php(97):
SoapClient->initiatePayment(Array) #2 {main} thrown in
/aaaaaaaa/Source/developement/PHP/ver1/subscribe.php on line 97
I got things working using curl,
I use This
as a reference and code working.
Thankx

Zend_Log with mail

Has anyone succeed to send an mail(SMTP GOOGLE) with Zend_Log.I found this http://framework.zend.com/manual/en/zend.log.writers.html
Chapter 32.2.4. Writing to Email but by default it's using mail(), but I want to use SMTP.So until now my code looks like this:
$mailconf = array('ssl'=>'ssl',
'auth' => 'login',
'username' => 'mymail#gmail.com',
'password' => 'mypass',
'port'=>'465');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailconf);
$mail = new Zend_Mail();
$mail->setFrom('from.website#example.com')
->addTo('mysecondmail#site.com');
$writer = new Zend_Log_Writer_Mail($mail);
// On fixe le sujet du mail
$writer->setSubjectPrependText('Important Log Events');
// Only email warning level entries and higher.
$writer->addFilter(Zend_Log::WARN);
$loggerZendMail = new Zend_Log();
$loggerZendMail->addWriter($writer);
$loggerZendMail->log('unable to connect to database',Zend_Log::WARN);
I'm getting this error:
Fatal error: Uncaught exception 'Zend_Log_Exception' with message 'Unable to send mail' in C:\wamp\www\zf_log\Zend\Log\Writer\Mail.php:256 Stack trace: #0 C:\wamp\www\zf_log\Zend\Log.php(84): Zend_Log_Writer_Mail->shutdown() #1 C:\wamp\www\zf_log\Zend\Controller\Action.php(512): Zend_Log->__destruct() #2 C:\wamp\www\zf_log\Zend\Controller\Action.php(512): IndexController->indexAction() #3 C:\wamp\www\zf_log\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('indexAction') #4 C:\wamp\www\zf_log\Zend\Controller\Front.php(945): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 C:\wamp\www\zf_log\index.php(30): Zend_Controller_Front->dispatch() #6 {main} thrown in C:\wamp\www\zf_log\Zend\Log\Writer\Mail.php on line 256
Any suggestions?
You need to set the transport for Zend_Mail to use
Example:
Zend_Mail::setDefaultTransport($transport);
I would check if SMTP is enabled on server.
Use TLS instead of SSL also check if the port 587 works
so the below config should work
$mailconf = array('ssl'=>'tls', 'auth' => 'login', 'username' => 'mymail#gmail.com', 'password' => 'mypass', 'port'=>'587');