Anti XSS PHP Library (Class 'voku\\helper\\AntiXSS') - php

I've been trying to use this Anti XSS Library: https://github.com/voku/anti-xss/blob/master/README.md
But I'm getting following error:
AH01071: Got error 'PHP message: PHP Fatal error: Class 'voku\\helper\\AntiXSS' not found in /var/www/vhosts/example.com/httpdocs/xss.php on line 6\n'
Here's the code I'm using:
<?php
use voku\helper\AntiXSS;
require_once __DIR__ . '/vendor/autoload.php';
$antiXss = new AntiXSS();
$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
echo $antiXss->xss_clean($harm_string);
?>

You need to require the autoload before you reference the class.
require_once __DIR__ . '/vendor/autoload.php';
use voku\helper\AntiXSS;
Otherwise, this dependancy namespace will not be loaded into memory in the context, as it is loaded inside the autoload.php file. This is why it says class not found.
Also Make Sure You've Installed via "composer require"
composer require voku/anti-xss

Related

php composer class not found when library is installed

I'm quite new to using composer and I am not too sure what I am doing at this point. I am currently trying to use this Nmap library I found. now once I have this library installed using this commandcomposer require willdurand/nmap
I created a index.php file with
<?php
require __DIR__ . '/vendor/autoload.php';
$hosts = Nmap::create()->scan([ 'example.com' ]);
$ports = $hosts->getOpenPorts();
echo $ports;
?>
This is what my composer.json file
{
"require": {
"willdurand/nmap": "^0.5.0"
}
}
When I run this I get PHP Fatal error: Uncaught Error: Class 'Nmap' not found in /var/www/html/nmap.php:5. I have Nmap installed on my Unix system. Any help on this issue would be great.
When you do not define a current namespace, PHP looks for any references classes in the root namespace. However, it cannot find Nmap in the root namespace because it is defined in the ´Nmap´ namespace.
You have to either add the namespace to the class defenition:
$hosts = \Nmap\Nmap::create()->scan([ 'example.com' ]);
Or, add a using statement for this class at the top of your file: (under <?php ofcourse)
use Nmap\Nmap;

Problem with composer not autoloading certain package

I have a package I created that I included with composer called ShinePHP (https://packagist.org/packages/adammcgurk/shine-php#0.0.4), and it has been working fine being autoloaded etc..., but right now the autoload just all of a sudden shut off. There is no reason for this, I didn't touch the composer.json file, I really didn't touch anything with the library, I'm just getting the error:
Fatal error: Uncaught Error: Class 'ShinePHP\EasyHttp' not found in
/Applications/XAMPP/xamppfiles/htdocs/manager-reporting/src/index.php:12
Stack trace: #0 {main} thrown in
/Applications/XAMPP/xamppfiles/htdocs/manager-reporting/src/index.php
on line 12
Here is how that code is being called:
<?php
declare(strict_types=1);
session_start();
require_once 'vendor/autoload.php';
require_once 'model/Page.php';
require_once 'model/Auth.php';
use ShinePHP\{Crud, CrudException, HandleData, HandleDataException, EasyHttp, EasyHttpException};
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
try {
EasyHttp::checkHttps();
} catch (EasyHttpException $ehe) {
// Google Analytics
echo $ehe->getMessage();
exit;
}
I know it is a problem with this particular library, because I also have PHPMailer installed here with Composer, and I just tried instantiating PHPMailer using:
$mail = new PHPMailer(true);
And it worked no problem.
I've ran:
composer dumpautoload
And got this response:
Generating autoload files
Why is my autoload broken for my ShinePHP package?
Autoloading rules in your package (adammcgurk/shine-php) are incorrect. Since your classes are inside of src/ShinePHP directory your autolading rules should look like that:
"autoload": {
"psr-4": {
"ShinePHP\\": "src/ShinePHP/"
}
},

Push Notification: Fatal error: Class 'EccFactory' not found in pushnotification/vapidkeys.php on line 124

I am trying to implement push notification.
I downloaded web-push library from: https://github.com/web-push-libs/web-push-php
The first thing I wanted was VAPID keys .
filename is vapidkeys.php, this file is inside pushnotification directory, and in pushnotification directory I have web-push-php-master directory.
<?php
require('web-push-php-master');
use Minishlink\WebPush\WebPush;
var_dump(VAPID::createVapidKeys());
?>
But the above line throws following error:
Fatal error: Class 'EccFactory' not found in pushnotification/vapidkeys.php on line 124
Please help me solve this issue, I am new to push notification and namespaces
You have to get web-push-php with Composer, so that all the dependencies are installed.
Install Composer
Run composer require minishlink/web-push. This will install web-push-php and all its dependencies in the vendor folder.
In your PHP file, require it : require __DIR__ . '/vendor/autoload.php';
Here's a basic example that uses web-push-php: https://github.com/Minishlink/web-push-php-example
Hope this helps.
HTTPD Website Only Generate Key,Your website is HTTP can't generate Key

when use phpwhois in cakephp show me Error: Class 'phpWhois\WhoisClient' not found

I downloaded phpwhois from here,
and copied it in vendor folder in cakephp.
But when I load whois class in controller :
App::import('Vendor', 'phpWhois\Whois', array('file' => 'phpWhois/Whois.php'));
It shows me this error :
Error: Class 'phpWhois\WhoisClient' not found
File: \app\Vendor\phpWhois\Whois.php
Since whois class extend WhoisClient.
What should I do?
install using following composer command
php composer.phar require "phpwhois/phpwhois":"~4.0"
Add following line in bootstrap.php
require APP . 'Vendor/autoload.php';
spl_autoload_unregister(array('App', 'load'));
spl_autoload_register(array('App', 'load'), true, true);
and add this before before controller's class definition
use phpWhois\Whois;

Symfony2 console command

I followed Symfony2 create a basic command line.
<?php
// application.php
use Acme\Command\GreetCommand;
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new GreetCommand);
$application->run();
But I received the faltal Error:
Fatal error: Class 'Symfony\Component\Console\Application' not found
According to http://symfony.com/doc/current/components/using_components.html, you need to include the autoloader at the top of your PHP script.
// update this to the path to the "vendor/"
// directory, relative to this file
require_once __DIR__.'/../vendor/autoload.php';

Categories