HTML PHP Special Characters showing question mark


I was developing a french website for a customer yesterday and at the same time, when I was templating the site to php, I found out that all the french accents got turned into a question mark, �  <– this really..

What’s wrong?

I already had UTF-8 in my headers

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

and it was still not working.

Resolution:

It turns out that I had not saved the file in UTF-8, so I had to open up Notepad++ which is my main coding IDE, and go to Encoding -> Convert to UTF-8 without BOM

Solved!

Read More

PHProjekt6 – Integration with LDAP


Since there’s not so much documentation online, I had to struggle a bit to get LDAP working.. but here’s the code 🙂 Hopefully it’ll help some other people.

Of course, there are better ways to get this running, but that’s my quick fix.

File: application/Default/Controllers/LoginController.php

Change the line $success = Phprojekt_Auth::login($username, $password, $keepLogged); to this

try {

function tryLdap($username,$pass) {
//Try the ldap thing
if (strlen(‘cisolve.local’) != 0) {
$username = $username . ‘@’ . ‘mydomain.local’;
}
$ldapconn = ldap_connect(‘ldap://’ . ‘xxx.xxx.xxx.xxx’);   // 2
if (!$ldapconn) {
die(‘Cannot connect to server’);
return false;
}
$ldap_secure_connection = ‘no’;          // 3
if ($ldap_secure_connection == ‘tls’) {
if (!ldap_start_tls($ldapconn)) {
ldap_close($ldapconn);
die(‘Cannot connect securely to server’);
return false;
}
}
$ldapbind = ldap_bind($ldapconn, $username, $pass);
ldap_close($ldapconn);
if ($ldapbind) {
return true;
} else {
return false;
}
}
$ldapSuccess = tryLdap($username,$password);
if($ldapSuccess==true) {
$success = Phprojekt_Auth::login($username, $keepLogged);
} else {
$success=false;
throw new Phprojekt_Auth_Exception(‘Invalid user or password’, 1);
}

File: library/Phprojekt/Auth.php

Change line

public static function login($username, $password, $keepLogged = false)

to

public static function login($username, $keepLogged = false)

In the same file,

comment-out the following:

// The password does not match with password provided
/* if (!Phprojekt_Auth::_compareStringWithPassword($password, $setting->getSetting(“password”, $userId))) {
throw new Phprojekt_Auth_Exception(‘Invalid user or password’, 2);
} */

That should do the trick. Do not forget to change the values from the LoginController.php to reflect your domain settings.

Read More