PHP ldap_connect always returns false - php

We currently have a class like below
class LDAP {
private static $_singleton ;
public static function getInstance()
{
if(is_null(self::$_singleton)) {
self::$_singleton = ldap_connect("ldap://xxx.xxx.xxx.xxx:389");
if(self::$_singleton){
ldap_set_option(self::$_singleton, LDAP_OPT_PROTOCOL_VERSION, LDAP_VERSION);
$b = ldap_bind(LDAP::getInstance(), LDAP_BINDDN, LDAP_BINDPW) ;
}
}
return self::$_singleton ;
}
}
But we always get "false" while trying to "connect" (ldap_connect).
My colleagues don't have any problems when they try to authenticate on their localhost. Only on my localhost we have problems (with the same configuration and same sources).
We tried to reinstall php (8.0.19) and also try with other 8.0.x version but always the same issue.
We also tried to copy/past from other host, but always the same issue.
Also try to compare apache\bin files.
Any idea why ldap_connect method always returns false ?

Related

Configure services based on env var in Symfony 5.4

I am working on a project that uses many env vars and I used php files (rather than yaml files or xml) to deal with configurations.
I am trying to this code :
// config/may_conf_name.php
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('my_extension', [
...
]);
// CLIENT_TYPE is an env variable
if ('http' === (string) env('CLIENT_TYPE')->string()) {
$services->alias(AbstractClient::class, HttpClient::class);
} else {
$services->alias(AbstractClient::class, AwsClient::class);
}
...
}
Unfortunately, env('CLIENT_TYPE')->string()) isn’t parsed
dump(
(string) env('CLIENT_TYPE')->string())
)
// output
^ "%env(string:CNT_CLIENT_TYPE)%"
Obviously, when I do this, it works for me :
if (isset($_ENV['CLIENT_TYPE']) && 'http' === $_ENV['CLIENT_TYPE']) {
....
}
So, my question is there a way to get my ‘CLIENT_TYPE’ env var like env('CLIENT_TYPE')->string()? Is it "clean" to do this with $_ENV['CLIENT_TYPE']?
Thank you!
Look at https://symfony.com/doc/current/service_container.html#binding-arguments-by-name-or-type
In your service.yaml or php in your case you can bind variable which will be autoimported inside autowired services.
In Yaml
bind:
$clientType: '%env(CLIENT_TYPE)%'
In php
->bind('$clientType', '%env(CLIENT_TYPE)%')
Then in any service where you want to use your environment var :
public function __construct(string $clientType)
$clientType will be autowired automatically with your binded configuration.
I don't know if this is exactly what you're looking for, dont hesitate to comment i will update my answer, but i hope it will at least give you an idea of what to do.
I asked for your SF version because autowiring is automatically working on 5.4 if you did not disabled it
If CLIENT TYPE is empty, it is not related to your symfony configuration. It mean that your env var is not properly written to your current env file.

Setting up Yii2 project in localy system in Window XAMPP getting error

I'm setting up Yii2 project in locally system in window XAMPP and I'm getting an error:
Declaration of common\components\Request::validateCsrfToken() should
be compatible with
yii\web\Request::validateCsrfToken($clientSuppliedToken = NULL)
But the code is working fine on Ubuntu server.
Here is my validateCsrfToken() method:
public function validateCsrfToken()
{
if($this->enableCsrfValidation && in_array(Yii::$app->getUrlManager()->parseRequest($this)[0], $this->noCsrfRoutes)){
return true;
}
return parent::validateCsrfToken();
}
This issue is because you are using strict PHP in Windows, but not in Linux. You own function common\components\Request::validateCsrfToken() should be compatible with yii\web\Request::validateCsrfToken(). This means, it needs to have the same signature.
What you can do at the moment is to change your own function to
public function validateCsrfToken($token = NULL) {
if ($this->enableCsrfValidation && in_array(Yii::$app->getUrlManager()->parseRequest($this)[0], $this->noCsrfRoutes)) {
return true;
}
return parent::validateCsrfToken($token);
}
You need to do this every time you are rewriting one of those functions (i.e. beforeAction, afterAction, beforeSave and many more...)

Deploying a Symfony App to Google App Engine

I’ve read the documentation on https://cloud.google.com/appengine/docs/php/symfony-hello-world and I managed to deploy the Hello World app, but when I try with my symfony app I have his error:
InvalidArgumentException in XmlFileLoader.php line 259: Unable to parse file "(…) DependencyInjection/../Resources/config\web.xml".
In app.yaml I set the env variables:
env_variables:
GCS_BUCKET_NAME: "pinterpandaibucket"
CACHE_DIR: "gs://pinterpandaibucket/symfony/cache"
LOG_DIR: "gs://pinterpandaibucket/symfony/log"
And I overloaded the AppKernel.php functions:
public function __construct($environment = null, $debug = null)
{
// determine the environment / debug configuration based on whether or not this is running
// in App Engine's Dev App Server, or in production
if (is_null($debug)) {
$debug = !Environment::onAppEngine();
}
if (is_null($environment)) {
$environment = $debug ? 'dev' : 'prod';
}
parent::__construct($environment, $debug);
// Symfony console requires timezone to be set manually.
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
// Enable optimistic caching for GCS.
$options = ['gs' => ['enable_optimsitic_cache' => true]];
stream_context_set_default($options);
$this->gcsBucketName = getenv('GCS_BUCKET_NAME');
...
public function getCacheDir()
{
if ($this->gcsBucketName) {
return getenv('CACHE_DIR');
}
return parent::getCacheDir();
}
public function getLogDir()
{
if ($this->gcsBucketName) {
return getenv('LOG_DIR');
}
return parent::getLogDir();
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
?>
The functions which write to the file system are redirected to the bucket.
Could you help me to find what modifications are missing in my app.
I hope this topic will help someone else because the Google cloud documentation isn't very up to date.
Thank you in advance and sorry if I don’t speak English very well I’m a French IT student.
Augustin
I have spent many an hours on this horrible bug, and what I found was this issue happens on the Dev AppServer, but not in production. I believe it is an issue with the implementation of the xml.so php extension in that environment.
This is fixed in the symfony starter app with the method fixXmlFileLoaderBug, which gets called in web/app.php. So ensure this is being called, and you should be good to go.
If you're experiencing this bug in Production, or you continue to experience this issue even after calling this function, please let us know by filing an issue on github.

Unable to connect to my database server using the provided settings

I got this error after i created my DB "Unable to connect to my database server using the provided settings"
Here is code....
* Database Loader
public function database($params = '', $return = FALSE, $active_record = NULL)
{
// Grab the super object
$CI =& get_instance();
// Do we even need to load the database class?
if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
{
return FALSE;
}
require_once(BASEPATH.'database/DB.php');
if ($return === TRUE)
{
return DB($params, $active_record);
}
// Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
// Load the DB class
$CI->db =& DB($params, $active_record);
}
This actually doesn't have anything to do with your code. Your application can't connect to the database using the provided database settings: (Host, username, and password).
Ensure that you have a database with the correct name and have a Database user setup with access privileges to that database.
The config file is typically located at application/config/database.php.
I've finally find a solution for I think is the same problem that you're having, it's due to the php version that you have at your server, in my case I have php 5.3.5 in my localhost but in my server I had php 5.2.6 I wasn't go further but the main problem was the avoiding notification when a function doesn´t work properly, specifically in "mysql_driver.php"
line 150.
return #mysql_set_charset($charset, $this->conn_id);
get rid of "#", to see the real problem, I found this, stopping each certain part of my script till I finally found where was the problem.
to solve this you can set "$this->use_set_names" to true, so that you can use the if condition near to the line I've pointed out to you.
If the problem wasn't this, probably is something similar, you can test each part of your script (debugging).

PHP works locally, not on server

I've been developing a custom CMS using Codeigniter locally and I've just gotten to the point where I need to upload it to a staging server to do some more testing.
Everything works except for the sidebar section of the site that uses a widget system. I initially thought it was just differences between PHP versions, as I am running 5.4.4 locally and the server was 5.3. After upgrading the server to 5.4.7, the sidebar is still not appearing. I get no error, just nothing displays.
This is the Widget library code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Widgets {
private $_ci;
protected $parser_enable = FALSE;
public function __construct() {
$this->widgets();
}
public function widgets(){
$this->_ci =& get_instance();
}
public function build($view,$data=array()){
$view = get_class($this).'/'.$view;
$subdir = '';
if (strpos($view, '/') !== FALSE)
{
// explode the path so we can separate the filename from the path
$x = explode('/', $view);
// Reset the $class variable now that we know the actual filename
$view = end($x);
// Kill the filename from the array
unset($x[count($x)-1]);
// Glue the path back together, sans filename
$subdir = implode($x, '/').'/';
}
$widget_view = APPPATH.'widgets/'.$subdir.'views/'.$view.EXT;
if(file_exists($widget_view)){
$widget_view = '../widgets/'.$subdir.'views/'.$view.EXT;
if($this->parser_enable){
$this->_ci->load->library('parser');
return $this->_ci->parser->parse($widget_view,$data,TRUE);
}
else{
return $this->_ci->load->view($widget_view,$data,TRUE);
}
}
return FALSE;
}
public function __get($var) {
static $ci;
isset($ci) OR $ci = get_instance();
return $ci->$var;
}
}
Does anything jump out that could cause it not to display?
Is there anything I should be looking at to make it compatible, such as server modules? What on the server could be affecting this?
EDIT:
I have the widgets residing in the following path:
/public_html/application/widgets/recent_news/views/view.php
The $widget_view = 'widgets/'.$subdir.'views/'.$view.EXT; variable is returning widgets/Recent_news/views/view.php which is getting passed to:
if(file_exists($widget_view)){
return $this->_ci->load->view($widget_view,$data,TRUE);
}
The application path in $widget_view doesn't seem to be correct on the staging server, so file_exists() returns false and doesn't load the view (which would have an incorrect path anyways).
I just can't seem to make it read the correct path, any suggestions?
If it's a staging server, go into the php.ini file and set
error_reporting = E_ALL | E_STRICT
display_errors = On
This will output whatever errors it finds so you can debug it.
Ended up just needing to subdir = strtolower($subdir);
Thanks for the help everyone

Categories