Can print_r $_SESSION object, but cannot access it? - php

First, a bit of background info. I'm working on a multi-site project, 3 cities each with their own installation of a custom CMS type thing. The client doesn't want to pay out for more than one SSL certificate, and despite my suggestion won't even look into a wildcard SSL. My job is to create a unified payment gateway that sits on domain.com/paypment.php, the sites themselves sit on subdomains e.g cityx.domain.com.
Now, on the original payment page the code accesses an object created by the CMS called $_SESSION['member_obj'], and at some point in the code detects the user's account level using:
if ($_SESSION['member_obj']->data['account_level']==1)
So, this works all fine and dandy without any problems, but as soon as I use the same object on my script it breaks. I would like to point out that my code is sitting on the root domain, and the working code on a sub - I have made the $_SESSION variables available to all subdomains using:
ini_set('session.cookie_domain', '.domain.com');
Now, the odd part, the object exists but when I try to use the ->data['account_level'] method, it dies on me. I know the object exists becasue I can print_r the object and I get the following:
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Member
[table] => members
[data] => Array
(
[id] => 1689
[title] => mr
[firstname] => Testy
[surname] => McTesters
[age_range] => 18-24
[gender] => male
[email] => xxxxxx
[username] => xxxxxx
[password] => xxxxxx
[account_level] => 1
[joined] => 1326290317
[password_reset] =>
[password_reset_date] => 01/01/1970
[last_active] => 1326881531
[status] => active
[contact] => 0
[third_party] => 0
[notifications] => 0
[terms] => 1
[dummy] => 0
[override_account] => 0
[premium_request] => 1
[password_reset_date_original] => 1970-01-01
)
followed by a load of other stuff.
So, could anyone be kind enough to explain to me how an object can exist, but not be accessible?

Could it - __PHP_Incomplete_Class - be because you forgot to include the class definition for the class that encapsulates this data?

You will have to load the class Member prior to starting the session.
Check so your session.auto_start is set to off in your php.ini.

Related

How to get an object array's field?

I currently receive an array with this structure:
Array
(
[0] => Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => apple-tv-ad
.jpg
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 36555
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => /private/var/tmp/phpe6INuk
[fileName:SplFileInfo:private] => phpe6INuk
)
)
When I try to print_r($file[0]['originalName']); I receive a 500 internal server error. I try to upload a file via an AJAX call. Once my mediaUpload method is called, I want to make the database entry with the appropriate values received through this array. I am just stuck at how to access it. Any help would be appreciated.
Thanks!
Use the getClientOriginalName() method. (Sorry for the short answer, but that's pretty much all there is to it.)
$name = $file[0]->getClientOriginalName();
The UploadedFile object has different accessor methods you can use to get all the different pieces of information you need. They're all there in the API docs I linked.

EOAuthUserIdentity getting error on getting token

I am using jorgebg/yii-eoauth library. I use the library with Yii EAuth extension. By requirements yii eauth
Requirements
Yii 1.1 or above
PHP curl extension
loid extension
EOAuth extension
Well, I come across with this problem. I checked it in local with linkedin account (no social accounts work on local server, except linkedin ) and it works perfectly. But login system doesn't work on server. Can you help me in this case ? Thanks in advance !
I didn't write my code here, because I thought, the problem doesn't depend on my code. If it is not, I can put here necessary code.
EDIT:
Error was :
Argument 1 passed to EOAuthUtils::GetAccessToken() must be an instance of
OAuthConsumer, instance of __PHP_Incomplete_Class given, called in
protected/extensions/eoauth/EOAuthUserIdentity.php on line 138 and defined
In line 138 of EOAuthUserIdentity.php was written:
// Upgrade to access token.
$token = EOAuthUtils::GetAccessToken($consumer, $token, $oauthVerifier,
$this->provider->access_token_endpoint);
I put logger pre($consumer,1); before above code. and I had in local:
OAuthConsumer Object
(
[key] => 7........k
[secret] => s........r
[callback_url] =>
)
I had on server:
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => OAuthConsumer
[key] => 7.........k
[secret] => s........r
[callback_url] =>
)
the same php version on local and server
You need load class before unserialize object. If u don't do this, object unserialize to __PHP_Incomplete_Class.
see PHP problem with "__php_incomplete_class"

Debugging in CodeIgniter (and MVC)

Often times I feel the need to dump a variable for debugging purpose. In CodeIgniter I am struggling to do that since I cannot simply "echo" a variable without passing it to the view first, which I think is pain-staking. I have read the official documentation, though I had found a good solution with the log_message function but cannot make it work, even though I successfully made the "logs" folder writable and changed the "threshold" as advised. Any suggestions?
https://www.codeigniter.com/user_guide/general/errors.html
It's not good practice, but you can output anything to the browser at any point in execution (from core classes, libraries, models and controllers) by simply using print_r() at the point you want to output the info.
Of course, this will sometimes not display as there may be redirects/routes/etc that take the user to the next step in the controller execution, but if you want to suppress this (again, for debug purposes only), you can use:
print_r($string_or_variable_to_debug);
die();
The die() command will stop all execution and leave you with just the info you want to output.
Using log_message() is better practice, but it's difficult to understand why you're not having success there if you say you've followed the following steps:
Make sure that your logs folder is set to be writable
Set $config['log_threshold'] to 2, 3 or 4
Used the function like so: log_message('debug','Message you want to log');
If you want to use print_r() to nicely format an array or object inside the log message, then you'll need to set the second parameter of print_r() to TRUE, like so:
log_message('debug',print_r($array_or_object,TRUE));
You need to set your $config['log_threshold'] in file config.php since by default it's 0 (no logs)
0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages
I think the answer is you are looking for is:
Codeigniter - Developer's Debug Helper
You can add this file to application/helper folder. Then autoload vayes_helper in application/config/autoload.php for generic use. Then all you need to is writing:
vdebug($variable); // In Controllers, Models, Libraries, Helpers
<?=vdebug($variable)?> // In View files
log_message('debug',print_r($array_or_object_you_want_to_print,TRUE));
This will print your array nicely into log . Following is the output example :
[1] => Array
(
[uid] => 10049082
[phone_id] => 2
[friend_status] => 0
[friend_event_hide_status] =>
)
[2] => Array
(
[uid] => 10042768
[phone_id] => 4
[friend_status] => 3
)
[3] => Array
(
[uid] => 10078255
[phone_id] => 6
[friend_status] => 2
)
[4] => Array
(
[uid] => 10078255
[phone_id] => -1
[friend_status] => 1
[name] => Rajesh
)
[5] => Array
(
[uid] => 10078255
[phone_id] => -1
[friend_status] => 1
[name] => ritesh kumar
)
[6] => Array
(
[uid] => 10078255
[phone_id] => -1
[friend_status] => 1
[name] => Le
)

Zend Rest Server is not reading protected object variables

I am new to zend framework and I am working on REST web service API. While my model output is protected object variables Zend_Rest_Server(). It is unable to handle that and throw an error.
Array
(
[0] => Webservices_Models_Token Object
(
[_id:protected] => 1
[_token_key:protected] => 123
[_mapper:protected] =>
)
)
While why model is returning above result, I am getting error. I got this result from zend model mapper.
Oh Dear!
You seem to have arrived here by error, or the page you are seeking
has been removed and can no longer be displayed.
Perhaps you are looking for a page that has been moved during the
recent improvements to our website. An error occurred ** This needs to
be altered before go live Exception information:
Message: Invalid Character Error
Bellow output works fine and generating xml from $this->_server = new Zend_Rest_Server()
Array
(
[0] => stdClass Object
(
[id] => 1
[token_key] => 123
)
)
Can anyone tell me whats the problem?
How can I solve it?
This is did the trick for me. toArray()
$select = $this->getDbTable()->select()->where($where);
return $this->getDbTable()->fetchAll($select)->toArray();
Thanks.

CakePHP On Last step of ACL setup

I know there are several threads asking similar questions - but I havent found any real answers to solve this specific syntax error, I have followed the tutorial over and over again and still end up with these error - I know its looking for a missing node in relationship between the ACL and ACO - ugh, please help
Warning (512): DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:
Aro: Array
(
[User] => Array
(
[id] => 1
[username] => admin
[group_id] => 1
[created] => 2012-06-15 14:20:44
[modified] => 2012-06-15 14:20:44
)
)
Aco: controllers/Pages/display [CORE/Cake/Controller/Component/Acl/DbAcl.php, line 79]
It looks like your app can't find the aco record for the display action of the Pages controller. The quickest way to ensure you have all your aco's loaded into your db is use the AclExtras Plugin, this will scan through your controller files and add all actions to your aco table.

Categories