PasswordHash not working with CodeIgniter - php

I have put the files I downloaded from http://www.openwall.com/phpass/ to application/libraries
In my controller, I am using this code -
$params = array(
'phpass_hash_strength' => 8,
'phpass_hash_portable' => FALSE
);
$this->load->library('PasswordHash', $params);
$password = $this->passwordhash->HashPassword($pwd);
I am getting these errors -
A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 3
Filename: libraries/PasswordHash.php
Line Number: 116
A PHP Error was encountered
Severity: Warning
Message: strpos() [function.strpos]: Empty delimiter
Filename: libraries/PasswordHash.php
Line Number: 116
Update
Removed PasswordHash.php, using SimpleLoginSecure now.

I had the same issue whilst integrating PasswordHash into Symfony2.
To solve it, I renamed the PasswordHash method to __construct.
In theory, PHP 5+ should look for a method with the same name as the class if it can't find a constructor (http://php.net/manual/en/language.oop5.decon.php). My guess is that the class name resolves differently once a namespace is added (a requirement for my integration), but I've not investigated at all.

I think your problem is you are trying to use a generic PHP object as a CodeIgniter library. You can't just do that. You'll need to modify the original code to work, or download one of the contributed libraries already designed for CodeIgniter.
CodeIgniter libraries have some restrictions (such as how they are instantiated), so just dropping any file into the libraries folder won't work.

Related

Laravel 3 - PHP Warning: in_array() expects parameter 2 to be array

I am working with a code that was not written by me. It is a Laravel 3 application, it is giving me the following error:
PHP Warning: in_array() expects parameter 2 to be array, null given in /Users/use/Documents/project/laravel/error.php on line 87
Can you give me pointers on how to debug it? It is giving error in the file which was included in the framework. Also I using the php's inbuilt server to run the application. Does that cause problems? Any pointers are helpful.
PS: I am on a mac.
After looking at the source code it appears that you are getting the error from this file:
// laravel/error.php
// line 86
if (in_array($code, Config::get('error.ignore')))
{
return static::log($exception);
}
The method appears to be looking for the error.ignore config variable:
// application/config/error.php
// line 16
'ignore' => array(),
Check the application/config/error.php file, make sure that 'ignore' is set to an array. If it already is, then you likely have an error in one of the other config files which is corrupting the array.
Hopefully this helps and shows the steps you can take in tracking down the source of an error.
You can get this also if you're using composer and the required files have not been installed after a fresh checkout of the project. To resolve:
$ composer install
Or similar. To actually get a head on this information I had to throw $exception in the error.php file around line 87, then I saw the reason in the Apache error logs.
Most of this errors is about of parameters definition bug.
for example sometimes coder write
protected $guarded = 'title';
instead of
protected $guarded = ['title'];
That makes the paroblem

Error with PHP CodeIgniter common.php

I am using CodeIgniter and I have a problem
the code very simple just few row in the controller ,this is my controller
<?php
class Site extends Controller {
function index() {
echo 'i am here';
}
}
And this are the errors:
1- Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 130
2-Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 136
3-A PHP Error was encountered
Severity: 8192
Message: Assigning the return value of new by reference is deprecated
Filename: libraries/Loader.php
Line Number: 255
4-A PHP Error was encountered
Severity: 8192
Message: Assigning the return value of new by reference is deprecated
Filename: database/DB.php
Line Number: 133
I don't know where is the problem, certainly the code is correct but where is the problem. Any suggestions?
& is used in PHP to pass an object to a method / assign a new object to a variable by reference. It is deprecated in PHP 5 because PHP5 passes all objects by reference, but other vars default to by value.
To fix this error:
Update to the latest version of CodeIgniter, really!
Recently I faced the same prob, I was using codeigniter 1.7 and PHP 5.2.6 everything was working great, but after upgrading PHP to 5.3 the below error starts coming:-
Deprecated: Assigning the return value of new by reference is deprecated
The reason behind it is same as mentioned by #Amal , & is used in PHP to pass an object to a method / assign a new object to a variable by reference. It is deprecated in PHP 5 because PHP5 passes all objects by reference
For more info Refer to
Assigning the return value of new by reference is deprecated
So if you are creating your code from scratch, then better to use all the latest things, use codeigniter 2.1.4
But if you have your codebase in some old codeigniter version, then better to degrade your PHP (which is not recommended) till the time you move on to newer version.

Error with sphinx php api class used in symfony2 as a service

I use sphinx php api as a service in a symfony2 project when I want to search a term in an index i got this warning
Warning: Invalid argument supplied for foreach() in /var/www/domain.com/Symfony2/src/project/myBundle/services/SphinxClient.php line 997
this is the line 997
foreach ( $this->_weights as $weight )
so I added a test befor foreach() like this if(!empty($this->_weights))
the same error appaires in each foreach so I added the same test.
then an other error appaires
Notice: Undefined property: prject\MyBundle\services\SphinxClient::$_socket in in /var/www/domain.com/Symfony2/src/project/myBundle/services/SphinxClient.php line 563
I was loking for the problem origin for hours.
thanks for your help in advance.
In sphinxapi.php file used old constructor.
Delete string ( near 430 )
function SphinxClient()
and write:
public function __construct()
and all very well.
Don't forget to set namespace in file (I renamed sphinxapi.php to SphinxClient.php) and write in begin it:
namespace Acme\MyBundle\Sphinx;
Your path may be something else.
Without seeing the source of the file, not a lot can do to help.
IN the standard sphinxapi.php class that comes with sphinx the varaiables are all class variables, so $this->_weigths is an array. Maybe that was missed when it was poted to Symfony

Connecting to the database in a Created Library - CodeIgniter

I have a little issue right now and its bugging me, hopefully one of you guys will be able to help me out.
Basically I'm creating a library to use in CodeIgniter and I'm getting this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Functions::$db
Filename: libraries/Functions.php
Line Number: 11
The Database library is already on autoload aswell as my functions library:
$autoload['libraries'] = array('database','session','encrypt','functions');
The Functions.php file is located in the application/libraries folder accordingly.
Line number 11 consists of this:
$this->db->where('username', $data);
Not sure as to why the db is an undefined property?
It's probably because you need to get the CI instance first since not everything is loaded yet:
$ci =& get_instance();
$ci->db->where('username', $data);
See if that helps. Also see the instructions here.

Third-party library not loading in Expression Engine 2.0

I'm developing a properties module for Expression Engine that's to take properties from Rightmove's BLM format and populate a database, and then those properties be searchable from the front-end.
I've found a CodeIgniter library (http://biostall.com/codeigniter-rightmove-blm-parser-library) that does the heavy lifting of the BLM files. However, I can't seem to load it.
My code in mcp.properties.php looks like this:
$config = array();
$this->EE->load->library('rightmove_v3_parser');
$this->rightmove_v3_parser->initialize($config);
$data['properties'] = $this->rightmove_v3_parser->process();
print '<pre>'; print_r($data['properties']); print '</pre>';
exit;
The library files are in a libraries sub-folder in my properties add-on folder under /system/expressionengine/third_party/.
However, when using the above code, I get the following error in Expression Engine:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Properties_mcp::$Rightmove_v3_parser
Filename: properties/mcp.properties.php
Line Number: 44
Fatal error: Call to a member function initialize() on a non-object in /Users/Martin/Sites/expressionengine/system/expressionengine/third_party/properties/mcp.properties.php on line 4
Where am I going wrong? Why can't I bundle this library with my add-on and call it within my add-on?
You've missed the EE object when referencing the library. So after loading the library you should use
$this->EE->rightmove_v3_parser
to access it, rather than
$this->rightmove_v3_parser
Have you included the library at the top of your plugin, i could be wrong but I don't think loading a library like that will work from a library subdir in your third_party plugin folder. Try including the library at the top of your plugin.

Categories