Cant tell if phpactiverecord is connecting to database - phpactiverecord

I am writing a web service for a droid app adn trying to use phpactiverecord. I am not using an mvc. I cannot tell whether it is connecting to my database correctly because I don't know what it returns when it fails or if it just can't be used without an mvc.
<?php
require_once '../libs/php-activerecord/ActiveRecord.php';
ActiveRecord\Config::initialize(function($cfg)
{
$cfg->set_model_directory('../libs/php-activerecord/models');
$cfg->set_connections(array(
'development' => 'mysql://username:password#localhost/dbname'));
});
//$json=$_GET ['json'];
$json = file_get_contents('php://input');
$obj = json_decode($json);
//echo $json;
$data = Users::all();
$user_name = $data->user_name;
echo($data);
$password = $data->password;
$posts = array(name =>$user_name,
password =>$password
);
header('Content-type: application/json');
echo json_encode(array('posts'=>$posts));
?>
It throws a 500 error when I try to go to the page which isn't very helpful.

I figured it out but thanks for trying to help. My hosting server has a wierd structure that required my path to include a bunch of extra stuff that would be unlikely to happen to anyone else... basically my include pat was wrong. turning on error reporting pointed out the problem quickly.

Related

SMSA Tracking status [duplicate]

I'm making my first attempt to connect to a SOAP server from PHP, and I'm not understanding how to log in and get the data I need. The service I'm trying to connect to is the Hawley USA service http://hawleyusa.com/thcServices/StoreServices.asmx). I've been looking at a few posts on how to connect, and I get the basics. I've verified that I have SOAP enabled in my PHP, and I'm just trying to get an inventory list. Here's the code I'm using:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://hawleyusa.com/thcServices/StoreServices.asmx?WSDL";
$login_id = 'mylogin_id';
$password = 'mypassword';
$client = new SoapClient($wsdl_path);
try {
echo "<pre>\n";
print($client->InventoryList(array("LoginID" => $login_id, "Password" => $password)));
echo "\n";
}
catch (SoapFault $exception) {
echo $exception;
}
However, when I run this code, I get this error:
SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /Users/steve/Sites/mysite/hawley_client.php:12
When debugging, I can see the $client instance initiated, so I'm not sure why I'm getting this error.
Second question: Am I passing the user ID and password correctly?
Thanks.
Update: I threw in $client->__getLastRequest, and this is what I got:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hawleyusa.com/thcServices/">
<SOAP-ENV:Body>
<ns1:InventoryList/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So I can see that I'm missing my login ID and password. How do I add them to my InventoryList call?
You're close. Looking at the WSDL the InventoryList method takes an object called "request". Modify your call line slightly:
$client->InventoryList(array("request" => array("LoginId" => $login_id, "Password" => $password));
Probably it's not the same case but it also gives the same error if you don't specify empty strings in fields you don't need to use, taken from http://www.sitepoint.com/forums/showthread.php?755549-SOAP-XML-Object-reference-not-set-to-an-instance-of-an-object
I my case the problem was in typo:
In given docs the filed name was documentShipmentAddress (and I was using this)
but in wdsl (schema) was:
shipmentAddress
So that could be the problem with this error message.
I have changed the field name to shipmentAddress and it solved the problem.

ejabberd: Saving of roster not working with external Authentication Script enabled

I have successfully configured an ejabberd server with an extauth script (perl).
It is working correctly and only allowing users from my mysql DB.
But following features are not working anymore: roster management, adding users to rosters, authorization of users (for adding them to the roster)
With the internal auth it works. Both times ejabberd is configured to use the internal amnesia db.
Please help me figure out, why it is not working with extauth enabled. Do I have to write my own methods in the extauth script? (That I don't really want...)
So after doing some research on my problem, I think that switching to the external authentication will not support roster management.
What I ended up doing is swichting back to internal authentication and using mod_admin_extra to add users and update passwords with this php script:
<?php
class Jabber
{
public static function registerAndAddToSharedRoster($userId, $sessionToken)
{
$url = "http://localhost:5280/rest";
$register = "register $userId jabber.YOUR_DOMAIN.com $sessionToken";
sendRESTRequest($url, $register);
$sharedRoster = "srg_user_add $userId jabber.YOUR_DOMAIN.com shared jabber.YOUR_DOMAIN.com";
sendRESTRequest($url, $sharedRoster);
}
public static function updatePassword($userId, $newPassword)
{
$url = "http://localhost:5280/rest";
$register = "change_password $userId jabber.YOUR_DOMAIN.com $newPassword";
sendRESTRequest($url, $register);
}
}
function sendRESTRequest ($url, $request)
{
// Create a stream context so that we can POST the REST request to $url
$context = stream_context_create (array ('http' => array ('method' => 'POST'
,'header' => "Host: localhost:5280\nContent-Type: text/html; charset=utf-8\nContent-Length: ".strlen($request)
,'content' => $request)));
$result = file_get_contents($url, false, $context);
return $result;
}
?>
Hope this helps someone!
This answer is late but it could help someone:
Contrary to #ben-marten's answer, Switching to the external authentication does support roster management.
When you add someone to the roster, ejabberd is 'calling' the isuser operation - check if it’s a valid user - you have to provide that method in the script: see ejabberd Developers Guide - External Authentication
I ignored that operation, and I could not add a user to the roster.
For other script examples see Authentication Scripts

Migrate this Zend Gdata code from ZF to ZF2

Sorry for such a bad question but I spend 2 hours without any success. Zend Docs are horrible ...
I have found this Zend_Gdata library and Picasa data API -- loader.php file missing, but its crashing at line 2 Class 'Application\Controller\Zend\Loader\StandardAutoloader' not found, which obviously isn't the correct path.
I am not sure why ZF does not use
...\vendor\ZF2\library\Zend\Loader\
Im using https://github.com/zendframework/ZendSkeletonApplication which is working, but nothing else works out of box with zf2 and all help topics are described incompletely. A mess in my eyes ...
However here is the code.
//Change this for your domain
$domain = 'yourdomain.com';
$email = 'ad...#yourdomain.com';
$passwd = 'p#ssword';
$user = 'jsmith';
$newuserpassword = 'secretp#assword';
//Connect as admin to Google Apps
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, Zend_Gdata_Gapps::AUTH_SERVICE_NAME);
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
$gdata = new Zend_Gdata_Gapps($client, $domain);
//Now change the user's password
$updateUser = $gdata->retrieveUser($user);
$updateUser->login->password = $newuserpassword;
$updateUser = $updateUser->save();
There's a new API that you can use even if Zend 1 or 2:
https://github.com/google/google-api-php-client
Here's the page with installation instructions and a getting started:
https://developers.google.com/api-client-library/php/
And here are the available services:
https://github.com/google/google-api-php-client/tree/master/src/Google/Service
Hope it help.
There's no such thing as Zend_Loader in zf2 and the code you have posted is for zf1. If you have the barebones application working, then you will already have the autoloader working correctly (I presume you're using MVC and this code is to go in a controller, not a single file).
If you have the autoloader setup correctly, you also don't need to use Zend_Loader::loadClass.. as they will be autoloaded.
As for Gdata in zf2 - you will need to get the package, which can be found here https://packages.zendframework.com/. Good instructions are here: Zend Framework 2.0.2 YouTube API
Converting the code from zf1 to zf2 should be pretty easy.
However, unfortunately the gdata package is no longer maintained, so you are advised to use https://code.google.com/p/google-api-php-client/

Is there any tools to check what is happening in Kohana at Auth?

So, there is problem - I have the order to write web-app on Kohana (no choice) and until yesterday I had no experience with this framework (only in Rails). But anyway I googled and created the authentification on site via net steps:
1: using standart SQL-code in Kohana I created tables for Auth.
2: tutn on ORM and Auth
3: create action login()
public function action_login()
{
$auth = Auth::instance();
if ($auth->logged_in())
{
return $this->request->redirect("welcome/view");
};
if ($_POST)
{
$user = ORM::factory("user");
$status = $auth->login($_POST["username"],$_POST["password"]);
if ($status)
{
$this->request->redirect("welcome/view");
}
else
{
echo "Failed to login";
}
};
$this->response->body(View::factory("login"));
}
But whatever I do I get echo "Failed to login";.
Is there any tools to define what's wrong happening ? Some logs ?
Or, may be, I do something wrong at common....
To answer your question: no there are no obvious tools to dig into Auth. You're best off going into modules/auth and look into the files and dump out information to Kohana::log or Kohana::debug to debug the errors.
I think the problem with your code is that in Kohana 3.2, $_POST is unset. You should use this instead:
$status = $auth->login($this->request->post("username"), $this->request->post("password"));
Should work after that.

Zend Framework google translate usage

I'm trying to translate automatic a string using the google translator! Using Zend_Http_CLient is not able to log in in the application and retrieve the translated words. It returns to me an authentication error.
I google and searched here something about it but had no success. Can someone give a hand on it and tell me where can I find some idea on how to use Zend_Gdata with Google Translate and authenticate at the service?
Thanks a lot, best regard's.
As far as i know Zend GData classes doesn't support google translate yet
source : http://framework.zend.com/manual/en/zend.gdata.html
in the same page you would find a link to this : http://code.google.com/p/gtranslate-api-php/
i had give it a simple try and it seems to be working BUT note the comment in the class declaration
Google requires attribution for their
Language API, please see:
http://code.google.com/apis/ajaxlanguage/documentation/#Branding
hopefully that would help
please provide the error message to make your question more clear
thanks
$client = new Zend_Http_Client('http://ajax.googleapis.com/ajax/services/language/translate', array(
'maxredirects' => 0,
'timeout' => 30));
$client->setParameterGet(array(
'v' => '1.0',
'q' => 'Привет',
'langpair' => 'ru|en'
));
$response = $client->request();
$data = $response->getBody();
$server_result = json_decode($data);
$status = $server_result->responseStatus; // should be 200
$details = $server_result->responseDetails;
$result = $server_result->responseData->translatedText;
echo $result;
die;
There's no official Google Translate, yet. But this translation adapter might help:
http://www.zfsnippets.com/snippets/view/id/35
Also, if you do use this, be sure to CACHE your results! You don't want to hammer the service over and over again for the same translations.