I've installed libsodium on Windows for PHP 7 and I'm developing my project with PHPStorm. I've also installed Halite from Paragonie which couldn't even be installable if the libsodium extension were not installed correctly. Also the IDE finds the used functions and when clicking on the variables and so on it opens up the fitting files of libsodium.
But unfortunately in my setup I get the following error:
Uncaught Error: Undefined constant 'Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE' in C:\Server\nginx-1.11.1\html\mywebsite\vendor\paragonie\halite\src\KeyFactory.php:344
My index.php file looks like the following:
<?php
require_once 'vendor/autoload.php';
spl_autoload_register(function ($class) {
require_once $class . '.php';
});
$router = new AltoRouter();
$router->setBasePath('/' . basename(__DIR__));
require_once 'config/routes.php';
$match = $router->match();
$GLOBALS['db'] = new \config\database(true, null);
try
{
if ($match) {
$routeController = new Modules\Core\RouteController($match);
echo $routeController->bootstrap();
}
}
catch (Exception $ex)
{
//#todo log every Exception
}
I'm also submitting my form with Jquery which leads successfully to the execution of the following function (which doesn't find the libsodium functions/variables):
public function hash($password)
{
$this->setEncryptionKey();
return Password::hash(
$password, // string
$this->encryption_key // \ParagonIE\Halite\Symmetric\EncryptionKey
);
}
public function check($stored_hash, $password)
{
try {
if (Password::verify(
$password, // string
$stored_hash,
$this->encryption_key
)) {
return true;
}
} catch (\ParagonIE\Halite\Alerts\InvalidMessage $ex) {
// Handle an invalid message here. This usually means tampered ciphertext.
throw new \Exception($ex);
}
}
I've installed the php_libsodium.dll in the extension directory and put the libsodium.dll in in the directory of the php server. Just for trying out i put it later also in system32 directory and in Syswow64 directory - both didn't change anything.
I just installed the halite library from paragonie with composer but using it is unfortunately harder than I thought. I also tried to use the libsodium extension without Halite but that lead to similar errors that the needed classes, constants and functions and so on were not found.
I've also tried to change my autoloader, but the strange thing anyway is that the IDE finds everything without problems but executing the script in the browser just don't.
In order to use Halite 2.x, you need to have:
Libsodium 1.0.9+ (preferably 1.0.10 if you have trouble compiling .9)
PECL Libsodium 1.0.3+ (preferably 1.0.6) compiled against libsodium 1.0.9+.
The easy way to verify that this is set up is:
<?php
use \ParagonIE\Halite\Halite;
var_dump(Halite::isLibsodiumSetupCorrectly());
If you want a little more specific information on what's failing, just run this instead:
<?php
use \ParagonIE\Halite\Halite;
// TRUE enables verbose output:
Halite::isLibsodiumSetupCorrectly(true);
Most likely, you'll need to uninstall/reinstall the PHP extension compiled against a newer version of the shared library.
There's an RFC under discussion for PHP 7.1 right now that will make this painless in the future, if accepted. The RFC passed, years later; libsodium will be in PHP 7.2.
Related
This is just happening today when I'm updating my website. Actually I didn't even touch this file but for some reason it shows error and my website can't be loaded.
Here is the problem
try {
return $object->{$method}(...$parameters);
} catch (Error | BadMethodCallException $e) { // "|" << this is the error
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {
throw $e;
}
if ($matches['class'] != get_class($object) ||
$matches['method'] != $method) {
throw $e;
}
static::throwBadMethodCallException($method);
}
I have tried to search about catch one of two exception but none. How can I solve this. I don't even know about trait. Thanks before
From exceptions documentation
In PHP 7.1 and later, a catch block may specify multiple exceptions
using the pipe (|) character.
You're developing on a machine with newer version of PHP but deploying on an older version. You really should consider using exact same version of PHP on both machines to avoid backward compatibility issues.
To solve your problem, you can choose a newer version of PHP if your hosting company offers such a feature, or downgrade the library you're using to a version compatible to the PHP version of your host. I don't recommend the second method, downgrading a package to deal with outdated dependencies is not a good idea.
I couldn't find any good resource/article yet now to connect Couchbase server in my Controller page. I have installed PHP SDK successfully. But my code is not working. Object is not properly called. See my test code here. Object for ex. CouchbaseCluster, openBucket is not getting called properly.
public function getConnection() {
// Connect to Couchbase Server
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
$bucket = $cluster->openBucket('beer-sample');
// Retrieve a document
$result = $bucket->get('aass_brewery-juleol');
$doc = $result->value;
echo $doc->name . ', ABV: ' . $doc->abv . "\n";
}
Please help me out what the namespace or use will be included there.
Thanks in advance for giving some good point or references on Symfony and Couchbase.
The official Couchbase PHP SDK, is not just a PHP library, they distribute their SDK through libcouchbase package and a PECL extension.
The installation process is well documented .
Once installed, make sure the extension is loaded by checking phpinfo.
Assuming that installation went through succesfully, you should be able to use the Classes, methods exposed by the PECL extention.
The issue you are likely facing is that you are using a class from the Global Space in a Namespaced Class.
Observe the \
$cluster = new \CouchbaseCluster('http://127.0.0.1:8091');
mostly will solve the issue you are facing .
I'm trying to use the API of a dutch site that's being used by schools in The Netherlands to keep track of the grades and other data of the students. You can find the documantation here: http://www.magister-api.nl/ (it's in Dutch).
I installed Wamp server and Composer, just like the documentation of the API tells. I also have the Curl PHP extension and Mcrypt PHP extension enabled in Wamp, just like the documentation tells.
I have the composer.json file in the project root with:
{
"require": {
"stanvk/magister": "~2.0"
}
}
I then executed Composer update.
The only code that I have is:
<?php
require 'vendor/autoload.php';
use Magister\Magister;
use Magister\Models\Grade\Grade;
new Magister($school, $username, $password);
$grades = Grade::all();
foreach ($grades as $grade)
{
echo $grade->CijferStr;
}
?>
It's the exact same code as given as example on the documentation website.
But when I then run it, I get these errors:
Errors
I tried a lot to solve the problem, but I can't seem to figure it out. It's the first time I'm using composer and packagist.
The first two errors are unrelated to composer or Wamp - you're simply using two variables that hasn't been defined, $username and $password (and possibly $school). The rest of the errors seems to stem from these having no value (the Magister object seems to try to request username.magister.net, and without a username .. that field is empty).
Provide the correct username and password and things will probably work as you expect.
I've install UUID using pecl and then i add the extension to php.ini.
The extension is correctly loaded but i get the error
PHP Fatal error: Call to undefined function uuid_make()
This is my code :
<?php
$uuid = v4();
echo $uuid;
function v4() {
$context = $uuid = null;
uuid_create($context);
uuid_make($context, UUID_MAKE_V4);
uuid_export($context, UUID_FMT_STR, $uuid);
return trim($uuid);
}
?>
Why i'm getting this error?
If i print the list of available function i don't have neither uuid_make and uuid_export.
Hi search around the web but i always find someone who use uuid_make and uuid_export.
I can't find documentation about this module.
Thanks
The uuid_make and uuid_export are from the OSSP uuid extension, which is completely different from the PECL extension (although they both have a function named uuid_create).
The PECL extension has very little documentation and several limitations (at least from what I can tell scanning the source, e.g., no support for UUID V5). The OSSP extension is complete but must be installed from source.
If you only need to occasionally generate UUIDs, one simple alternative could be installing a uuid utility (e.g., apt-get install uuid) then use something like exec.
I am using OAuth::fetch() example in PHP.net (Outh code. The cod i use is
<?PHP
try{
$oauth = new OAuth("consumer_key","consumer_secret",OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setToken("access_token","access_token_secret");
$oauth->fetch("http://photos.example.net/photo?file=vacation.jpg");
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
echo $oauth->getLastResponse();
} catch(OAuthException $E) {
echo "Exception caught!\n";
}?>
The Error message is
Fatal error: Class 'OAuth' not found in C:\wamp\www\Jesvin\MyTest1\test1.php on line 3
You do not have the OAuth class available to use. It is a php extension and not part of the core package, you will need to install it manually into wamp. First thing to do is check whether the extension is available but not loaded.
Your php extension library will be something like /path/to/wamp/php/ext (i do not use wamp so you will have to google for your path or look for yourself in your filesystem).
If you see an oauth extension, you can skip installing oauth, if you do not you need to get a precompiled dll, look here: http://downloads.php.net/pierre/ and seach for "oauth", there are 2 (not sure which one you should use, so pick one, and if it doesnt work try the other).
Download it and stick teh dll in your extensions directory along with teh other php extensions.
Then find your php.ini file (you can use a file with <?php phpinfo; ?> and load it in your browser to see where php.ini is). Find where the extensions are defined and either uncomment or add this line to your php.ini file
extension=php_oauth.dll
ensure the dll name in the code above is teh same as the one you downloaded and installed to the extension folder. Also make sure there is NO semi colon at the start of this line.
That should just about do it. Hopefully php will load the DLL fine and it will work. Using pre-comiled dll's doesn't always work, but in this instance it will hopefully work.