I have HTTP_Request2 installed on my server; pear list shows it in the list of installed packages. But the following php file:
<?php
ini_set("include_path", '/path/to/php:' . ini_get("include_path"));
if (class_exists('HTTP_Request2')) {
print("true");
} else {
print("false");
}
...returns false. I've also tried replacing the ini_set line with
include '/path/to/php/HTTP/Request2.php';
...but I get the same result. Is there something I'm missing, or something else I can check?
Simply setting the include path doesn't implicitly give you access to the code. You need to either set the include path and then use relative includes:
ini_set("include_path", ...);
require_once 'HTTP/Request2.php';
Or just use fully qualified includes:
require_once '/path/to/HTTP/Request2.php';
That said, HTTP_Request2 is kinda old and I'd instead recommend using something like Guzzle via composer.
Related
I'm new in vlucas/phpdotenv and I want to test it before using it in my project so I made a test folder and installed vlucas/phpdotenv in it and this is my code page:
<?php
require_once realpath(__DIR__ . "/vendor/autoload.php");
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$app_name = getenv("APP_NAME");
echo $app_name;
?>
and there is no output I only get a blank page and when I make var_dump($app_name); I get an error
bool(false)
What is the problem?
For anyone who finds this and wonders why theres is not working. getenv was marked unsafe a while back, you must instantiate dotenv in your script with Dotenv::createUnsafeImmutable to be able to use getenv() rather than $_ENV, although it is not advised to do so.
I had the same problem as you, but I solved it with the following code.
<?php
require './vendor/autoload.php';
Dotenv\Dotenv::createImmutable(__DIR__)->load();
$stripeSecretKey = $_ENV['STRIPE_SECRET_KEY'];
echo $stripeSecretKey;
.env file content
STRIPE_SECRET_KEY=sk_test_1234567890123456
I Used an old version From Node.js and an old version from vlucas/phpdotenv and it works!
I'm new on amphp and i'd like to try this very simple code first.
I downloaded amphp with composer for windows and save all folder created inside my project folder.
composer require amphp/http-client
Then my code is:
<?php
require __DIR__ . './autoload.php';
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Amp\Loop;
$stringa = 'http://www.google.it/';
$request = new Request($stringa, "GET");
$location = $request->getHeader("Location");
var_dump($location);
But I get always 'Fatal error: Uncaught Error: Class 'Amp\Http\Client\Request' not found'
Any suggest?
I use wamp local server with php 7.0
Also ,after, I need to yield all the code...
Here are a few things that look for:
Did the autoload.php get included correctly?
I see there is an unnecessary . before /autoload.php.
Did you use the correct class name with the correct namespace?
Did you run composer require amphp/http-client so that the libraries will be installed?
Do the library's files exist inside the vendor/amphp/http-client directory?
If you're on Windows, use \ in the require statement.
Apart from these, I can't think of why the library won't load. I hope this helps.
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.
I am trying to install xml diff ; https://github.com/mmacia/XMLdiff and i have not managed yet to make it work.Whenever i run any test example,i get
Fatal error: Interface 'PHPUnit_Framework_Test' not found in
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php on line 85
Has anyone managed to install and use the library.I am using xampp on windows.
I believe your problem has to do with PHPUnit's Autoloader.php not being included. This file sets the php spl_autoloadspl_register function which is responsible for loading in interfaces and classes like PHPUnit_Framework_Test.
According to this SO question, you have to include the autoloader file manually. Without knowing more about your set-up and how that particular library works, I would say do something like this in the appropriate file(s):
// define phpunit path
if ( ! defined('PHPUNIT_PATH')) {
// define an absolute path to your PHPUnit dir
// CHECK THIS, i'm not good with php on windows:
define('PHPUNIT_PATH','C:\xampp\php\PEAR\PHPUnit');
}
// Then include the autoloader like this:
include PHPUNIT_PATH.'Autoloader.php';
I hope this helps you or anyone else out.
Check execution flags for C:\xampp\php\PEAR\PHPUnit\Framework\Framework\Test.php
The file needs to be executable by the user who is launching tests (probably you).
This is the error I am receiving:
Fatal error: Class 'Validate' not found in C:\xampp\htdocs\final_project\validate.php on line 5
And here is my PHP code:
<?php
require_once 'Validate.php';
foreach($_POST as $name => $value)
{
$valid = Validate::string($value);
}
?>
I do not understand what I am missing. I installed --alldeps for the validate package, and the PEAR include path is also correct. Validate_CA is not giving me any errors, but it is not properly validating either.
PHP parses the include_path in order of precedence. This means that when a relative path is passed to require(), include(), fopen(), file(), readfile() or file_get_contents(), PHP will start looking in the first directory. If the file is found, it includes it. If not, it will continue to the next and repeats the process.
Consider the following include path:
include_path = ".:/php/includes:/php/pear"
and the following PHP script:
<?php
require('MyFile.php');
PHP will look for MyFile.php in the following order:
./MyFile.php (Current Directory)
/php/includes/MyFile.php
/php/pear/MyFile.php
The reason why you cannot load Validate.php is you already have a file called validate.php (remember, paths are not case-sensitive on Windows, but are on UNIX) in your current directory. Therefore, PHP includes your file instead of the file corresponding to PEAR::Validate since yours is found before PEAR's in the include_path order of precedence.
Simply renaming your file to something else than validate.php should fix your problem. If it still doesn't work, try echoing the return value of get_include_path() to make sure it really is set right.