How to solve require error in Codeigniter 3 - php

I am trying to use require
require_once (__DIR__."./../config/config.php");
When I run this code, I got No direct script access allowed.
How I should solve this?

Related

Installing PHPMailer with Composer [duplicate]

This question already has answers here:
Class Firebase\JWT\JWT not found
(5 answers)
Closed last year.
I feel like I am almost there. (I could be wrong though)
from the root of my apache server (/usr/local/var/www)
I ran
composer require phpmailer/phpmailer
I've now got the folder system
/usr/local/var/www/vendor/phpmailer/phpmailer
In this folder, there is a src folder, and in that folder are basically all the files I think I need to include on the php page where I want to use PHPmailer.
On the PHP page where I want to use PHPMailer, I have at the top:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
and in the page I am calling
$mail = new PHPMailer(true); //Argument true in constructor enables exceptions
I am getting an error message
Error: Class "PHPMailer\PHPMailer\PHPMailer" not found in /usr/local/var/www/xxx.php
It seems like something isn't linking up correctly.
Alex Howansky posted a comment:
You need to source composer's autoloader, typically via something like require_once 'vendor/autoload.php';.
Ken Lee a comment:
Add the three lines: require './Exception.php'; require './PHPMailer.php'; require './SMTP.php'; after the line use PHPMailer\PHPMailer\Exception; (change to the actual path for the 3 files please) , retry and see what happens
Both suggestions fixed the problem. I'm going with the vendor/autoload.php solution.

php require_once autoload.php causing 500 error

hi everyone I'm writing a code where I want to use the autoload.php and I had written it as
<?php
session_start();
require_once "database.php";
require_once '/root/vendor/autoload.php';
use Twilio\Rest\Client;
I'm using this code to run my login_auth.php this code is written in the top of the page, I don't know what is the issue is but if I run this code with terminal by command php login_auth.php this works correct and gives me the output I'm looking for, but if the same thing I run with postman https://demo.conitor.in/PageMyCell/login_auth.php I'm getting error of 500 internal server error, I'm not sure whether issue is with autoload.php or what, but here I'm using twilio so I'm using the autoload.php.

Loading class in regualr php file in Laravel project

I have a laravel project and in it, I create a regular (.php) file that I am posting some data to. In that file, I want to use a class that I installed using composer in the Laravel project. When I post data to the page I am getting the error No such file in directory and require(): Failed opening required 'vendor/autoload.php. How can I resolve this my project is almost complete if I can get this working.
I've tried: require "class name" but the same error.
PHP file posting to:
<?php
require "vendor/autoload.php";
require 'vendor\lcobucci\jwt\src\Builder.php';
require 'vendor\lcobucci\jwt\src\Signer.php';
//I've tried using these require statements
use \vendor\Lcobucci\JWT\Builder;
use \vendor\Lcobucci\JWT\Signer\Hmac\Sha256;
someFunctiion(){
// do stuff with function from class
}
?>
I expect that when I post to this page, the function from the class I am 'using' will be called but instead, it's saying require() failed to open class.

Require paths not working using google api php library

My problem is the next one,
I tried to integrate the google login using OAuth 2.0 feature into my company backend.
I tested it on my domain , www.gabrielestevez.com, everything here works perfect, there is no problem with the require paths, everything runs smothly
But , the company backend directories has the following structure
I'm using a mvc framework developed by me , the Google_SL.php file contains the class where I make the first two require_once
require_once 'Google/Client.php';
require_once 'Google/Service/Oauth2.php';
which works fine, but then when it goes to the client.php and is trying to load this class
require_once 'Google/Auth/AssertionCredentials.php';
is not working , this is the error
An error occurred in script '/home/xxx/public_html/admin/hmf/Core/library/auth/Google/Client.php' on line 18: require_once(Google/Auth/AssertionCredentials.php) [function.require-once]: failed to open stream: No such file or directory
Date/Time: 9-19-2014 11:50:29
, I don't want to change manually all the path within this library because I know there is got to be a better solution to this
any input is appreciated.
for future reference
I fixed my issue using this
set_include_path($_SERVER['DOCUMENT_ROOT'] . '/admin/hmf/Core/library/auth/' . PATH_SEPARATOR . get_include_path());
Try use __DIR__ to get the current directory of the script. Not exactly sure where your AssertionCredentials.php is, but try something like
require_once(__DIR__ . '/Google/Auth/AssertionCredentials.php');

How to setup a php client Thrift 0.9.1 ...

I'm trying to setup a php client for RPC with a HBase Thrift server but I'm getting some errors at the begining ... I've compilated the HBase.thrift file (with the 0.9.1 compiler) and I've put the 2 generated files like bellow (/ is the root of my project, I'm using apache server on ArchOS) :
/include/Hbase.php
/include/Types.php
I've included the lib folder of thrift0.9.1/lib/php/lib (composed of Thrift and sub folders) under / and so I've the following file system :
/include/HBase.php
/Types.php
/Thrift/Base
/ClassLoader
/Exception
/ext
...
To be able to use my service (HBase.php) I've to load files so my code is the following :
<?php
$GLOBALS['THRIFT_ROOT'] = PHYSICAL_PATH;
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TMessageType.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Factory/TStringFuncFactory.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TType.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
//hbase thrift
require_once ('Hbase.php');
require_once ('Types.php');
?>
When I'm charging the different files, I'm getting an error for this line --require_once ('Types.php');-- and the error is : Fatal error: Class 'Thrift\Exception\TException' not found in /var/www/html/POCThrift2/include/Types.php on line 1266
I understand it like : When I tried to include Types.php, the Thrift\Exception\TException namespace was not use (despite the use Thrift\Exception\TException; in the beginig of the Types file) but I don't know why I'm getting his error ... can you help me ? Does anyone has encountered this problem before ? Thx in advance, I'm stuuuck right now ...

Categories