I have MAMP Pro installed running php 5.2.13. When I try to initialize a HTTP-Request
$r = new HttpRequest('http://example.com/', HttpRequest::METH_GET);
it tells me:
"Class 'HttpRequest' not found in ...".
What do I need to do to 'install(?)' it?
You must enable http extension:
http://www.php.net/manual/en/http.setup.php
Or you can try new HTTP_Request2:
sudo pear install --alldeps HTTP_Request2-alpha
And then:
$req = new HTTP_Request2('your.url');
$req->setMethod('POST');
$req->setHeader("content-type", $mimeType);
$req->setBody('');
$response = $req->send();
Contemporary Answer for MAMP 2.0 and HTTP_Request2:
Go into your MAMP/bin/php/php5.3.6/bin/ and run
./pear install --alldeps HTTP_Request2
Restart your server and test with the following code, from the PEAR repository:
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
try {
$response = $request->send();
if (200 == $response->getStatus()) {
echo $response->getBody();
} else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
} catch (HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>
Don't forget the require_once statement!
You need to enable the extension ...
add the following to your php.ini
extension = php_http.dll
Apparently that was asked a lot:
http://php.bigresource.com/Track/php-33sNme7A/
Related
i have tried installing phpmyadmin on arch linux but every time i open localhost/phpmyadmin,i get this text.
PHP 7.2.5+ is required.
Currently installed version is: ' . PHP_VERSION . '
'); } // phpcs:disable PSR1.Files.SideEffects define('PHPMYADMIN', true); // phpcs:enable require_once ROOT_PATH . 'libraries/constants.php'; /** * Activate autoloader */ if (! #is_readable(AUTOLOAD_FILE)) { die( '
File ' . AUTOLOAD_FILE . ' missing or not readable.
' . '
Most likely you did not run Composer to ' . '' . 'install library files.
' ); } require AUTOLOAD_FILE; global $route, $containerBuilder, $request; Common::run(); $dispatcher = Routing::getDispatcher(); Routing::callControllerForRoute($request, $route, $dispatcher, $containerBuilder);
i have installed php and this its version
PHP 8.1.8 (cli) (built: Jul 9 2022 06:10:37) (NTS)
i have also tried following all the steps in arch documentation (https://wiki.archlinux.org/title/phpMyAdmin)
but when i try to open the url(localhost/phpmyadmin),it outputs a blank page with no
body so i had to reset all the configs to default.help me out.thanks alot
to solve this issue,i reinstalled everything again,followed the steps in (https://wiki.archlinux.org/title/phpMyAdmin) and in /etc/php/php.ini,uncommented the extension 'bz2 and mysqli'
I try to install via a web admin a module. The action call a function allowing via composer to install a library.
My problem is composer create everytime an htaccess inside my shop directory with an access denied.
Conclusion, it's impossible the display the website
I do not need this htaccess.
How to resolve this problem that.
/shop/.htaccess ===> do not need this files (create automatically)
/shop/composer.lock
/shop/composer.json
public function __construct()
{
static::$root = CORE::getConfig('dir_root', 'Shop');
static::$composerJson = static::$root . 'composer.json';
//define composer environment
putenv('COMPOSER_HOME=' . self::$root);
putenv('COMPOSER_CACHE_DIR=' . CORE::BASE_DIRECTORY . '/Work/Cache/Composer/');
}
public static function install($library = null)
{
if (self::checkExecute() == true) {
if (is_null($library)) {
$result = false;
} else {
$cmd = 'cd ' . self::$root . ' && composer require ' . $library . ' 2>&1';
exec($cmd, $output, $return); // update dependencies
$result = $output[2];
}
return $result;
}
}
Thank you.
I have used azure-sdk-for-php library and I am getting this error-Warning: require_once(WindowsAzure/Blob/Models/BlockList.php): failed to open stream: No such file or directory.
My code is as below-
define("__BLOBNAME__", "BLOBNAME");
define("__CONTAINERNAME__", "CONTAINERNAME");
define("__BLOBKEY__", "BLOBKEY");
//require_once('WindowsAzure\WindowsAzure.php');
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\Common\CloudConfigurationManager;
use WindowsAzure\Blob\Models\Block;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\ListContainersOptions;
use WindowsAzure\Blob\Models\CreateBlobOptions;
use WindowsAzure\Blob\Models\CommitBlobBlocksOptions;
use WindowsAzure\Blob\Models\BlobProperties;
$connectionString = "DefaultEndpointsProtocol=http;AccountName=" . __BLOBNAME__ . ";AccountKey=" . __BLOBKEY__ . "";
if (null == $connectionString || "" == $connectionString) {
echo "Did not find a connection string whose name is 'StorageConnectionString'.";
exit();
}
// Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
try {
// List blobs.
$blob_list = $blobRestProxy->listBlobs(__CONTAINERNAME__);
$blobs = $blob_list->getBlobs();
// iterate over blobs
foreach ($blobs as $blob) {
$options = new WindowsAzure\Blob\Models\CreateBlobOptions();
$options->setBlobCacheControl("public, max-age=604800");
echo 'setting ... ';
$blobRestProxy->setBlobProperties(__CONTAINERNAME__,$blob->getName(), $options);
}
} catch (ServiceException $e) {
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/library/azure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code . ": " . $error_message;
}
It seems that you failed to load the SDK file.
The recommended way to resolve dependencies is to install them using the Composer package manager.
Create a file named composer.json in the root of your project and add the following code to it:
json
{
"require": {
"microsoft/windowsazure": "^0.5"
}
}
Download composer.phar in your project root.
Open a command prompt and execute this in your project root
php composer.phar install
Then load the SDK in your code with:
require_once "vendor/autoload.php";
I am integrating Dropbox into my PHP based website. When i try to run the following code. i got this Fatal error: Call to undefined function readline() on the last line.
require_once "dropbox-sdk/Dropbox/autoload.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("app-info.json");
echo "<pre>";
print_r($appInfo);
echo "</pre>";
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
echo "<pre>";
print_r($webAuth);
echo "</pre>";
$authorizeUrl = $webAuth->start();
echo "1. Go to: " . $authorizeUrl . "\n<br>";
echo "2. Click \"Allow\" (you might have to log in first).\n<br>";
echo "3. Copy the authorization code.\n<br>";
$authCode = \trim(\readline("Enter the authorization code here: "));
I have come through different forum where people said it will work in Command line , But I don't understand how? Any idea ?
Or just use this to simulate it
if(!function_exists("readline")) {
function readline($prompt = null){
if($prompt){
echo $prompt;
}
$fp = fopen("php://stdin","r");
$line = rtrim(fgets($fp, 1024));
return $line;
}
}
readline() is for running on the command line not via the web browser.
To check you have it installed on your server, type:
php -i | grep Configure
Probably, you have not installed it and you should compile it yourself or ask your hosting admin to if they allow this.
Just had this issue on Ubuntu.
Found this answer: https://askubuntu.com/a/264329/166
The solution in this scenario was to install the package php5-readline.
I've installed apache on a debian server and added php. But if i try to create a .zip file it doesn't work. There's no error message but the .zip file doesn't get created.
Code:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
$zip->addFile('Banner1.png', 'Banner1.png');
$zip->close();
?>
Most likely, the user that php is running as (on debian, www-data by default) doesn't have writing permissions to the directory. Check the result of the various functions like this:
<?php
$zip = new ZipArchive();
$res = $zip->open('test.zip', ZipArchive::CREATE);
if (!$res){
echo 'Error while creating zip file: ' . $zip->getStatusString();
exit();
}
if (! $zip->addFile('Banner1.png', 'Banner1.png')) {
echo 'Error while adding Banner1: ' . $zip->getStatusString();
exit();
}
if (! $zip->close()) {
echo 'Error while closing: ' . $zip->getStatusString();
exit();
}
On a debian with default configuraiton, you can configure permissions with chown and chmod. For example, to allow the webserver to write to that directory, try
sudo chown www-data /path/to/directory/with/php/file
sudo chmod u+rwx /path/to/directory/with/php/file
Sûre your $res is good ?
if ($res === TRUE) {
echo 'ok';
$zip->addFile('Banner1.png', 'Banner1.png');
$zip->close();
} else {
echo 'failed, code:' . $res;
}