XML-RPC not working and using functions usage in Bugzilla - php

I am writing a program to extract a comment from the bug. So first using XML-RPC I am trying to connect to Bugzilla and do it via
putting http://bugzilla.yourdomainname.com/xmlrcp.cgi
So here is my code....
setCookieJar();
$oClient->setHttpClient($oHttpClient);
$aResponse = $oClient->call('User.login', array(array(
'login'=>'username',
'password' => 'password',
'remember' => 1
)));
//Log into bugzilla.
function getInfoBug(int $bugno)
{
$aResponse = $oClient->call('Bug.get($bugno)');
//this would just return bug no.
$aResponse = $oClient->call('Bug.get( ids => [$bugno], include_fields => [\'id\', \'comments\'] )');
//Getting info about bugs.
$final = $Client->call('Bug.get(comments($aResponse)');
//
return $final;
}
$bug = 1379;
echo $answer = getInfoBug($bug);
?>
So actually am not really sure if I am calling the function correctly from the Buzilla API and another problem that is coming is that
Warning: require_once(Zend/Loader/Autoloader.php) [function.require-once]: failed to open stream: No such file or directory in C:\Zend\Apache2\htdocs\Aakash\bugzilla.php on line 6
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader/Autoloader.php' (include_path='/usr/share/php/libzend-framework-php') in C:\Zend\Apache2\htdocs\Aakash\bugzilla.php on line 6
So am not really sure what is happening. Am just a beginner in PHP.

Check to see that Zend/Loader/Autoloader.php exists in the PHP include directory and that the permissions are set correctly for the user that your PHP script is being runas.

Related

Error due to blank lines appearing in the response, while creating a php webservice using nusoap

I'm getting below error while creating a sample php webservice using nusoap.
This page contains the following errors:
error on line 4 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.
On checking the network tab, I can see that XML output is generated on the 4th line. Cannot figure out why. There is no space before of after tags as I saw as potential reasons online.
<?php
require_once('lib/nusoap.php');
require_once('dbconn.php');
$server = new nusoap_server();
/* Fetch one set data */
function fetchSSData($SS_id){
global $dbconn;
$sql = "SELECT SS_id, SS_name FROM SS_soap where SS_id = :SS_id";
// prepare sql and bind parameters
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':SS_id', $SS_id);
// insert a row
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
return json_encode($data);
$dbconn = null;
}
$server->configureWSDL('SSsoapServer', 'urn:SSsoap');
$server->register('fetchSSData',
array('SS_id' => 'xsd:string'), //parameter
array('data' => 'xsd:string'), //output
'urn:SSsoap', //namespace
'urn:SSsoap#fetchSSData' //soapaction
);
$server->service(file_get_contents("php://input"));
After hours of searching found the answer. Adding ob_clean() in the beginning of php file clears the output buffer. This solved the problem for me.

Guide a newbie: PHP 7 warning: Warning: count(): Parameter must be an array or an object that implements Countable

After upgrading to PHP 7 I get the following error message in a really old WP theme. Unfortunately changing the theme is not an option right now, so I have to try to find a fix. I can kind of read PHP, but have a hard time writing it on my own, so I'd love some pointers on how to change this.
The Error message:
Warning: count(): Parameter must be an array or an object that implements Countable
The code that needs to implement Countable
if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE) {
$settings = $this['option']->get('warp_theme_options', array());
} else {
$settings = ($file = $this['path']->path('template:config')) ? file_get_contents($file) : array();
}
// set config or load defaults
if (count($settings)) {
$this->config = $this['data']->create($settings);
} else {
$this->config = $this['data']->create(file_get_contents($this['path']->path('template:config.default')));
}
From trying to read up on this I think the error is that count no longer allows Null? But how would I change the code if statement above to work then?

Prestashop Db::getInstance()->update() return Undefined variable

I tried to import my CSV file to update my products, it keeps give me time out and after 2 weeks, we ruled out the server is the problem ( we tried changing max_execution_time, memory_limit, or anything that we think would cause it)
The error logs showed following error:
PHP Notice: Undefined variable: return in /var/www/vhosts/22/xxxxxx/webspace/httpdocs/xxxxxx/controllers/admin/AdminImportController.php on line 1518
which is a customized code that we added to sort our products listing;
Following are the code
$prod_pos = get_object_vars($product);
if (isset($info['position']) && !empty($info['position']))
{
$update_prod_cat_id = array();
for ($i = 0; $i < count($product->category); $i++)
{
if (is_numeric($product->category[$i])){
$return &= Db::getInstance()->update('category_product', array(
'position' => $info['position'],
), '`id_category` = '.(int)$product->category[$i].' AND `id_product` = '.(int)$product->id);
}
else
{
$update_prod_cat_id[] = Category::searchByName($default_language_id, trim($product->category[$i]), true);
$return &= Db::getInstance()->update('category_product', array(
'position' => $info['position'],
), '`id_category` = '.(int)$pos_cat_id['id_category'].' AND `id_product` = '.(int)$product->id);
}
}
}
The funny thing is this code was working until we move the hosting to cloud hosting then every time we tried to upload a CSV file more than 300 lines, it will just timed out and the error log will show the above error!
I am wondering if the db_prefix needed for Db::getInstance()->update()
But I read it will automatically put it when we use this instance.
I am not sure. I tried everything I though it would work but it's not.
Any idea?
From what I see in the code, the varable $return is undefined on the two rows that is being assigned
May be the script really timeouts, but this can be confirmed during the debugging process. The code above seems OK.
The db prefix is automatically added in your case.

Odd issue with PHP namespace

I have slapped together a test PHP script. It would output some remote connection's geo ip based data. Nothing fancy, just a quick prototype.
But I am seeing an odd behavior, so I am asking here if somebody had any clues about it.
PHP is version 5.5.12 on Ubuntu 64 bit.
Here's some code from the geoip_test.php calling script:
require_once ('geoip_utils.php');
$server_geoip_record = geoip_record_by_name('php.net');
echo '<pre>PHP.net web server location: ' . print_r($server_geoip_record, 1);
echo '<br />PHP.net web server local time: ' . \df_library\getUserTime($server_geoip_record)->format('Y-m-d H:i:s');
Nothing fancy at all, isn't it?
Now the simple geoip_utils.php code:
<?php
namespace df_library;
require_once('timezone.php');
// Given an IP address, returns the language code (i.e. en)
function getLanguageCodeFromIP($input_ip)
{
};
// Given a geo_ip_record, it returns the local time for the location indicated
// by it. In case of errors, it will return the optionally provided fall back value
function getUserTime($geoip_record, $fall_back_time_zone = 'America/Los_Angeles') {
//Calculate the timezone and local time
try
{
//Create timezone
$timezone = #get_time_zone($geoip_record['country_code'], ($geoip_record['region'] != '') ? $geoip_record['region'] : 0);
if (!isset($timezone)) {
$timezone = $fall_back_time_zone;
}
$user_timezone = new \DateTimeZone($timezone);
//Create local time
$user_localtime = new \DateTime("now", $user_timezone);
}
//Timezone and/or local time detection failed
catch(Exception $e)
{
$user_localtime = new \DateTime("now");
}
return $user_localtime;
}
?>
When I run the calling script I get:
PHP Fatal error: Call to undefined function df_library\getUserTime() in /var/www/apps/res/geoip_test.php on line 5
The funny part is: if I add this debug code:
$x = get_defined_functions();
print_r($x["user"]);
I get this output:
Array
(
[0] => df_library\getlanguagecodefromip
[1] => df_library\gettimezone
[2] => df_library\getutcdatetime
[3] => df_library\getlocalizedtime
[4] => df_library\getutcdatetimeaslocalizeddatetime
[5] => df_library\getlocalizeddatetimeasutcdatetime
[6] => get_time_zone
)
First of all, I don't understand why the function names are converted to lower case.
But most of all, notice how index 0 shows the empty function function getLanguageCodeFromIP($input_ip) being defined, and that function is right above the one that the interpreter complains about as not being defined!
Why does PHP see the other function in that file but not the one I want to use?
Any ideas are welcome!
There is an extra semi-colon ; after the close bracket of function getLanguageCodeFromIP which causes PHP parser somehow unable to recognize the functions after getLanguageCodeFromIP.
As proven in OP's comment, removing the ; solved the problem.

Problem validating XML against XSD - PHP/schemaValidate

I'm trying to validate an XML file against an XSD using the function schemaValidate(String file) from DOMDocument.
When I validate it on other tools like online validators, it works fine, but in my program I always get this error and really can't find where it's coming from:
Warning: DOMDocument::schemaValidate(/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd): failed to open stream: Permission denied in /home/public_html/xxxx/xxxx.php on line 209 Warning: DOMDocument::schemaValidate(): I/O warning : failed to load external entity "/home/public_html/product/xxxx/xxxx/xxxx/xxxx/xsd/AdlSchema.xsd" in /home/public_html/xxxx/xxxx.php on line 209 Warning: DOMDocument::schemaValidate(): Failed to locate the main schema resource at '/home/public_html/product/xxxxx/xxxxx/xxxxx/xxxx/xsd/AdlSchema.xsd'. in /home/public_html/xxxx/xxxxx.php on line 209 Warning: DOMDocument::schemaValidate(): Invalid Schema in /home/public_html/xxxx/xxxx.php on line 209
So my question is, is there a way to get more details about this error (mainly the Invalid schema one) with DOMDocument functions? and if ever someone could tell what could cause that kind of errors that would be great (xml and xsd are kind of confidentials, sorry, but once again it is working just fine with a few other tools).
Thanks!
/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd): failed to open stream: Permission deniedThe php process doesn't have the necessary rights to access the xsd file.
Let's poke around a little bit and add some debug/info code
Please add
/* debug code start. Don't forget to remove */
// if there already is a variable you use as parameter for schemaValidate() use that instead of defining a new one.
$path = '/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd';
foreach( array('file_exists', 'is_readable', 'is_writable') as $fn ) {
echo $fn, ': ', $fn($path) ? 'true':'false', "<br />\n";
}
$foo = stat($path);
echo 'mode: ', $foo['mode'], "<br />\n";
echo 'uid: ', $foo['uid'], "<br />\n";
echo 'gid: ', $foo['gid'], "<br />\n";
if ( function_exists('getmyuid') ) {
echo 'myuid: ', getmyuid(), "<br />\n";
}
if ( function_exists('getmygid') ) {
echo 'myuid: ', getmygid(), "<br />\n";
}
$foo = fopen($path, 'rb');
if ( $foo ) {
echo 'fopen succeeded';
fclose($foo);
}
else {
echo 'fopen failed';
}
/* debug code end */
right before your call to schemaValidate().
I got the same problem using relative paths to XML and XSD schema files. But after I changed it to the absolute ones the problem disappeared.
For me the reason was that the libxml entity loader was disabled (libxml_disable_entity_loader(true);). It seems to have to be enabled to use this function. I switched to DOMDocument::validateSchemaSource since I don't want to have to enable the entity loader.

Categories