php require_once autoload.php causing 500 error - php

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.

Related

How to solve require error in Codeigniter 3

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?

PHP Cannot redeclare function error: Why am I getting this error?

I have two PHP scripts that include the same include file. Also, for testing purposes, I declared the same function that performs SOAP operations in both scripts. In other words, my scripts look like this:
#script1.php
include('include.php');
someFn();
function someFn() {
//SOAP code here
}
#script2.php
include('include.php');
someFn();
function someFn() {
//SOAP code here
}
Whenever I try to run one script and then the other, I get the following error:
PHP Fatal error: Cannot redeclare someFn() (previously declared in script1.php) in script2.php
I cannot understand why I'm getting this error. I've coded similar situations before, but never gotten this error, so I suspect that the executing of the SOAP code (specifically, the new SoapClient constructor and $client->__setSoapHeaders method) is causing this error.
What's also interesting is if I comment out the include file (which, by the way, does not have someFn defined in it) and then rerun the script, I don't get any errors and everything is fine.
What is happening here?
Thank you.
Edit: After playing around some more, I found out that if I have the following situation:
#script1.php
include('include.php'); //someFn defined in include.php
someFn();
#script2.php
someFn();
function someFn() {
//SOAP code here
}
And then run script2.php and then script1.php after that, I get the same error. It's almost as if after I run script2.php and close it, the process continues in PHP so that when I run script1.php, I get the error.
Any help would be greatly appreciated.
Thank you.
Edit #2: This is honestly the most confusing thing ever. I started over by creating two brand new files in the same directory as the other files and then all I added to both files was the following code:
<?php
include('include.php');
And when I run either file, I get all the SOAP output that was generated from the other files in the directory. I haven't bothered trying to restart the server, but at this point, I can only assume that something really weird is cached on the server.
Anyway, I resolved the issue by simply creating a new directory and then moving the file I wanted to that directory and re-executing it. By doing that, I got no errors and everything is fine.
Thanks everyone for your assistance.

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 ...

NetDNA MaxCDN api giving error

I am trying to use NetDNA to purge cached URLS from MaxCDN and not able to create the NetDNA object - gives me the following error message:
Fatal error: Class 'NetDNA' not found in purgeCacheDev.php on line 8
Any ideas where to look to resolve this error ?
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
require_once '../vendor/autoload.php';
$api = new NetDNA("aaa","bbb","ccc");
// get account information
echo $api->get('/account.json');
exit;
?>
Try this:
php composer.phar update -o
within your project folder.
Also make sure your IP(s) are whitelisted: http://support.maxcdn.com/tutorials/how-to-whitelist-your-server-ip-to-use-the-api/

Categories