Missing file error (XMLStream.php) using XMPP - php

I want to send message using XMPP and I have used this code:
include 'XMPP.php';
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
$conn = new XMPPHP_XMPP('hostname',5222, 'panelusername', 'panelpassword', 'xmpphp', 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
try {
$conn->connect();
$conn->processUntil('session_start');
$conn->presence();
$conn->message('senderusername', 'This is a test message!');
$conn->disconnect();
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}
But it gives me this error:
Warning: require_once(XMPPHP/XMLStream.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/xmppmessage/examples/XMPP.php on line 30
Fatal error: require_once(): Failed opening required 'XMPPHP/XMLStream.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/xmppmessage/examples/XMPP.php on line 30

In the XMPP.php file on line 30, change it from:
require_once 'XMPPHP/XMLStream.php';
to
require_once 'XMLStream.php';

Related

Handle SOAP fatal error when there is a connection issue

I'm trying to connect to a soap service using a WSDL file in php 5.6
The snippet below works fine if I'm on the network, but if I'm disconnected I get a fatal error.
try {
$soap_client = new SoapClient($wsdl_file, ['exceptions' => true]);
}
catch (SoapFault $fault) {
echo 'poop';
}
catch (Exception $exception) {
echo 'pee';
}
edit: it does seem to do something with the SoapFault, because I can see my 'poop' debug message, but it still results in a fatal error
These are the errors I get
Warning (2): SoapClient(): php_network_get_addresses: getaddrinfo failed: No such host is known.
Warning (2): SoapClient(http://soap.service.com/serivce.svc) [soapclient.soapclient]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known.
Error: SOAP-ERROR: Parsing Schema: can't import schema from 'http://soap.service.com/serivce.svc'
How can I gracefully handle the error so that php continues to run, so I can set a variable and render an HTML page indicating that there was a problem connecting
This was a cakephp issue
https://github.com/cakephp/cakephp/issues/8501
$restore = error_reporting(0);
try {
$soap_client = new SoapClient($wsdl_file, ['exceptions' => true]);
}
catch (SoapFault $e) {
trigger_error($e->getMessage()); // Overwrites E_ERROR with E_USER_NOTICE
}
finally {
error_reporting($restore);
}

PHP SSH2 ssh2_connect

So I have taken a example from php.net to see php ssh2 workings
so the code is
<?php
$connection = ssh2_connect('shell.example.com', 22);
if (ssh2_auth_password($connection, 'username', 'secret')) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}
?>
When I am putting wrong information it is giving me some error instead of telling me Authentication Failed.
The Error is
Warning: ssh2_connect(): php_network_getaddresses: getaddrinfo failed: Name not known in
/var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/ssh2.php on line 2 Warning: ssh2_connect(): Unable to connect to
shell.example.com on port 22 in /var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/login/ssh2.php on
line 2 Warning: ssh2_connect(): Unable to connect to shell.example.com in
/var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/login/ssh2.php on line 2 Warning:
ssh2_auth_password() expects parameter 1 to be resource, boolean given in /var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/login/ssh2.php
on line 4 Authentication Failed...
But when I am putting correct information it is not giving any error.
The problem is that shell.example.com doesn't actually exist and the call to ssh2_connect() fails to return a resource.
Your code should be checking to see if ssh2_connect() successfully makes a connection and returns a resource before attempting to use the resource with ssh2_auth_password().
$connection = ssh2_connect('some.valid.ssh.host', 22);
if (!$connection) {
throw new Exception("Could not connect to server.");
}
if (!ssh2_auth_password($connection, 'name', 'password')) {
throw new Exception("Authentication failed!");
}
// SSH connection authenticated and ready to be used.

PHP Login: failed to open stream: No such file

Greeting's I'm currently taking my first attempt at developing a login for my website. For this login I'm utilizing PHP and MySQL. My problem is that I keep recieving the error below... I've tried exhausted all possibilities of how to rename "require_once" input to my knowledge, but still know luck.
Warning: require_once(C:\Users\Derek\Fall_2013\PS-WebDesign\includes\constants.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\11311638\html\classes\Mysql.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'C:\Users\Derek\Fall_2013\PS-WebDesign\includes\constants.php' (include_path='.;C:\php\pear') in D:\Hosting\11311638\html\classes\Mysql.php on line 3
Below is the line of code that is producing the Fatal error, My question is have I not called the file correctly or is there code my feeble mind is missing? The error is on the 3rd line "require_once...."
<?php
require_once 'includes/constants.php';
class Mysql {
private $conn;
function __construct() {
$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die(
'You ***'d up.');
}
function verify_Username_and_Pass($un, $pwd) {
$query = "SELECT *
FROM users
WHERE username = ? AND password = ?
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
The path either needs to be an absolute path to the file you want to include or you need to add its location to your include path.
http://php.net/manual/en/function.set-include-path.php
is this include file in the root directory?
You should also remove the blank line above the include line.
Lsatly, the syntax for die should read die(mysqli_error() 'You ***'d up.');

How do I handle Warning: SimpleXMLElement::__construct()?

I'm getting this error when I run in local host, if internet is disconnected (if internet is connect its ok) I want to handle this error, "error can show " but want to handle not fatal error break on PHP page.
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]:
php_network_getaddresses: getaddrinfo failed: No such host is known.
in F:\xampp\htdocs\shoptpoint\sections\docType_head_index.php on line 30
but I'm trying to handle using try-catch. Below is my code
$apiurl="http://publisher.usb.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=78b0db8a-0ee1-4939-a2f9-d3cd95ec0fcc&trackingId=7000610&categoryId='5855855'";
try{
new SimpleXMLElement($apiurl,null, true);
}catch(Exception $e){
echo $e->getMessage();
}
How do I handle the error and my page can execute end of the project?
Using set_error_handler, you can do the following to convert any notices/warnings raised by SimpleXMLElement into a catchable Exception.
Take the following:-
<?php
function getData() {
return new SimpleXMLElement('http://10.0.1.1', null, true);
}
$xml = getData();
/*
PHP Warning: SimpleXMLElement::__construct(http://10.0.1.1): failed to open stream: Operation timed out
PHP Warning: SimpleXMLElement::__construct(): I/O warning : failed to load external entity "http://10.0.1.1"
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML'
*/
See how we get 2 Warnings before the the Exception from SimpleXMLElement is thrown? Well, we can convert those to an Exception like this:-
<?php
function getData() {
set_error_handler(function($errno, $errstr, $errfile, $errline) {
throw new Exception($errstr, $errno);
});
try {
$xml = new SimpleXMLElement('http://10.0.1.1', null, true);
}catch(Exception $e) {
restore_error_handler();
throw $e;
}
return $xml;
}
$xml = getData();
/*
PHP Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct(http://10.0.1.1): failed to open stream: Operation timed out'
*/
Good luck,
Anthony.
If for any reason you don't want to set up the error handler you can also use some libxml functions to suppress E_WARNING from raising:
// remembers the old setting and enables usage of libxml internal error handler
$previousSetting = libxml_use_internal_errors(true);
// still need to try/catch because invalid XML raises an Exception
try {
// XML is missing root node
new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>',null, true);
} catch(Exception $e) {
echo $e->getMessage(); // this won't help much: String could not be parsed as XML
$xmlError = libxml_get_last_error(); // returns object of class LibXMLError or FALSE
if ($xmlError) {
echo $xmlError->message; // this is more helpful: Start tag expected, '<' not found
}
}
// sets libxml usage of internal error handler to previous setting
libxml_use_internal_errors($previousSetting);
Alternatively you can use libxml_get_errors() instead of libxml_get_last_error() to get all errors. With it you can get all errors regarding parsing the XML as an array of LibXMLError objects.
Some helpful links:
https://www.php.net/manual/en/function.libxml-use-internal-errors.php
https://www.php.net/manual/en/function.libxml-get-last-error.php

unable to use variables defined in class

Hi i am trying to import the configuration variables from a config file that i had created
Config.php has
class Config
{
public $SERVERNAME = '*******';
public $SUSERNAME = '*********';
public $SPASSWORD = '*********';
public $DBNAME2 = '********';
}
for importing this variable in another file i tried
include('./Config.php') or die("error");
$cnfig = new Config();
But when i try to use $cnfig->DBNAME2 its not working
Please help to sole this problem.
Thank you.
EDIT
It was working in localsystem , when i tied to upload through web hosting it was not working.
Try below one
include ('./Config.php');
$cnfig = new Config();
echo "<pre>";print_r($cnfig);
Edit:
I am getting below output so it should be working for you too.
Config Object
(
[SERVERNAME] => *******
[SUSERNAME] => *********
[SPASSWORD] => *********
[DBNAME2] => ********
)
Edit:2
You can also do like this
(include('./Config.php')) or die("error");
$cnfig = new Config();
echo "<pre>";print_r($cnfig);
http://www.php.net/manual/en/function.include.php#39043
or has higher priority than include()
Error Ouput:
When only use include('./Config.php') or die("error"); it's giving below error.
Warning: include(1) [function.include]: failed to open stream: No such file or directory in D:\path_to_file\myConfig.php on line 2
Warning: include() [function.include]: Failed opening '1' for inclusion (include_path='.;D:\ZendServer\share\ZendFramework\library') in D:\path_to_file\myConfig.php on line 2
Fatal error: Class 'Config' not found in D:\path_to_file\myConfig.php on line 6

Categories