I added a namespace to my user.php file, this causes an error to be displayed :
Fatal error: Uncaught Error: Class 'User' not found in /var/www/html/login.php:9 Stack trace: #0 {main} thrown in
/var/www/html/login.php on line 9
I tried changing "new Database\Database();" to "new \PDO();" but that causes another error which I've been unable to resolve after spending hours on google, if anyone could help I'd much appreciate it, thank you.
user.php
<?php
namespace User;
// 'user' object
class User
{
login.php
<?php
include_once "config/core.php";
$page_title = "Login";
$require_login = false;
include_once "login_checker.php";
include_once "config/database.php";
include_once "objects/user.php";
include_once "libs/php/pw-hashing/passwordLib.php";
$database = new Database\Database();
$db = $database->getConnection();
$user = new User($db);
use User\User;
$user = new User($db);
Related
Project file structure
I'm getting
127.0.0.1:52368 [500]: GET /controllers/login - Uncaught Error: Class "App\Core\Database" not found in /path/to/my/Php/project/src/controllers/index.php:9
Stack trace:
#0 {main}
thrown in /path/to/my/Php/project/src/controllers/index.php on line 9
and the class firing an error
<?php
namespace App\controllers;
use App\Core\Database;
//$conn = Database::getConnection();
try {
$conn = new Database(__DIR__ . './../config.php');
} catch (\Exception $e) {
}
$query = "SELECT id, username, image, aboutme
FROM users
LEFT JOIN persons on users.id = persons.user_id
LIMIT 24";
$tbh = $conn->prepare($query);
$tbh->execute();
$persons = $tbh->fetchAll();
require_once basename("/") . 'views/index.view.php';
also my autoload_classmap.php
return array(
'App\\Core\\Database' => $baseDir . '/src/Core/Database.php',
'App\\Core\\DotEnv' => $baseDir . '/src/Core/DotEnv.php',
'App\\Core\\Router' => $baseDir . '/src/Core/Router.php',
'App\\Entity\\Person' => $baseDir . '/src/Entity/Person.php',
'App\\Entity\\User' => $baseDir . '/src/Entity/User.php',
And I'm launching server from src directory :
php -S localhost:8000
Any help would be appreciated. Thank you.
Edit ...
I'm calling index.php from url : localhost:8000 and even with this code in index.php
<?php
namespace App;
//use App\core\Database;
use App\Core\Router;
require 'functions.php';
//$config = require_once ('config.php');
//$db = new Database($config);
//require 'Entity/User.php';
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
$router = new Router();
$router->getRoute($uri);
//require 'router.php';
I'm getting
127.0.0.1:53738 [500]: GET / - Uncaught Error: Class "App\Core\Router" not found in
You must create a class and add data inside it .
prepare($query);
$tbh->execute();
$persons = $tbh->fetchAll();
require_once basename("/") . 'views/index.view.php';
}
I just created php web server and connected it to firebase. when I tried authentication, Sign up works just fine. but the problem is in Sign in. it keeps getting this error:
Fatal error: Uncaught Error: Call to undefined method Kreait\Firebase\Auth::signInWithEmailAndPassword() in /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php:24 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php on line 24
here my authentication code:
<?php
include("includes/db.php");
if(isset($_POST['signup']))
{
$email = $_POST['emailSignup'];
$pass = $_POST['passSignup'];
$auth = $firebase->getAuth();
$user = $auth->createUserWithEmailAndPassword($email,$pass);
header("Location:index.php");
}
else
{
$email = $_POST['emailSignin'];
$pass = $_POST['passSignin'];
$auth = $firebase->getAuth();
$user = $auth->getUserWithEmailAndPassword($email,$pass);
if($user)
{
session_start();
$_SESSION['user'] = true;
header("Location:home.php");
}
}
?>
and here's my database connection code:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Auth;
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyCHULFKW6Kl7FXZc3ZUTYL8fq0f90-kAJ0';
$firebase = (new Factory)
->withServiceAccount($serviceAccount, $apiKey)
// The following line is optional if the project id in your credentials file
// is identical to the subdomain of your Firebase project. If you need it,
// make sure to replace the URL with the URL of your project.
->withDatabaseUri('https://phpserver-f35e3.firebaseio.com/')
->create();
$database = $firebase->getDatabase();
?>
👋 I'm the maintainer of the SDK (kreait/firebase-php) you're using :)
Your error says
Call to undefined method Kreait\Firebase\Auth::signInWithEmailAndPassword()
but I don't actually see this method called in your code. A method called signInWithEmailAndPassword() doesn't exist as well, and you're using methods to initialize the SDK that have been deprecated for quite some time now - please make sure to be on the latest release of the SDK (4.40 at the time of this comment).
Once you have, you will have access to the Auth::verifyPassword($email, $password) method.
Your code could then look like this:
<?php
// includes/db.php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
$factory = (new Factory())->withServiceAccount(__DIR__.'/google-service-account.json');
$auth = $factory->createAuth();
// no closing "?>"
<?php
include("includes/db.php");
// Have a look at https://www.php.net/filter_input to filter user input
if (isset($_POST['signup'])) {
$email = $_POST['emailSignup'];
$pass = $_POST['passSignup'];
$user = $auth->createUserWithEmailAndPassword($email,$pass);
header("Location:index.php");
exit;
}
$email = $_POST['emailSignin'];
$pass = $_POST['passSignin'];
if ($email && $pass && $user = $auth->verifyPassword($email, $pass)) {
session_start();
$_SESSION['firebase_user_id'] = $user->id;
header("Location:home.php");
exit;
}
echo "Authentication failed";
If you have further questions concerning the SDK, I'd like to invite you the Discord community dedicated to the SDK.
Fatal error: Uncaught Error: Class 'htmlMimeMail' not found in E:\xampp\htdocs\surat\includes\common.php:293 Stack trace: #0 E:\xampp\htdocs\surat\index.php(10): include_once() #1 {main} thrown in E:\xampp\htdocs\surat\includes\common.php on line 293
This Error
I have configure my website in localhost I have php version is 7.4.
I have problem is class not found can please give me any suggestion
Thanx in advance
global $mail;
$mail = '';
$mail = new htmlMimeMail();
global $db;
global $db1;
global $db2;
global $dbtemp;
$db = '';
$db1 = '';
$db2 = '';
$dbtemp = '';
$db = new DB_Sql($config['DB_Host'], $config['DB_Name'], $config['DB_User'], $config['DB_Passwd'], false);
$db1 = new DB_Sql($config['DB_Host'], $config['DB_Name'], $config['DB_User'], $config['DB_Passwd'], false);
$db2 = new DB_Sql($config['DB_Host'], $config['DB_Name'], $config['DB_User'], $config['DB_Passwd'], false);
$dbtemp = new DB_Sql($config['DB_Host'], $config['DB_Name'], $config['DB_User'], $config['DB_Passwd'], false);
if(!$db->link_id())
{
die("Could not connect to the database");
}
This above code is my common.php code
and i include common.php file in index.php as below
include_once("./includes/common.php");
Not to sound ridiculous ... But do you actually include the library? As that would be about the only reason I can think off.
This is not necessary, unless you're in a function. Which you don't seem to be or you removed too much coding from your post.
global $mail;
Here is the code
<?php
include_once '../vendor/autoload.php';
use App\Student;
use App\Connection;
/*echo'<pre>';
var_dump($_POST);
echo '</pre>';*/
$student = new Student();
$student-> set($_POST);
echo "success";
$student-> store();
I can access the Student class and its methods but when uses this page to insert data show the error message in the title.Any quick answer will b highly appreciated.
Thanks
Mizan
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once('/include/adLDAP.php');
$adldap = new adLDAP();
$username = "user123";
$password = "pass123";
$authUser = $adldap->authenticate($username, $password);
if ($authUser === true) {
echo "<p>User authenticated successfully</p>";
}
else {
echo "User authentication unsuccessful";
}
$result=$ldap->user_groups($username);
print_r($result);
?>
I am using this class http://adldap.sourceforge.net/ and authentication works fine, but it gives me the following error:
Notice: Undefined variable: ldap in /web/protected/protected.php on line 18
Fatal error: Call to a member function user_groups() on a non-object in /web/protected/protected.php on line 18
Line 18 is:
$result=$ldap->user_groups($username);
Never used this class before, so I am unsure of why it is giving me that error, any help is appreciated.
When instanciating the adLDAP class, you're storing the instance object in $adldap :
$adldap = new adLDAP();
But, later, you are trying to use $ldap :
$result=$ldap->user_groups($username);
That $ldap variable doesn't exist -- hence the notice.
And as it doesn't exist, PHP considers it's null
And null is not an object -- which means you cannot call a method on it -- which explains the Fatal Error.
I suppose you should replace this line :
$result=$ldap->user_groups($username);
By this one :
$result=$adldap->user_groups($username);
Note the $adldap instead of $ldap, to use the instance of your adLDAP class, instead of a non-existing variable.