Posts

Showing posts with the label php

Use PHP to perform an LDAP Bind to Windows Active Directory for User Authentication

This example shows some basic LDAP bind lookups on a Windows 2003 active directory server. The sequence is: Connect  Bind using privileged user  search for 'dn' of supplied credentials re-bind using this dn and password of supplied credentials unbind The per-requisite is that php_ldap modules are loaded and compiled.  These are fairly standard now days.  In fedora it was just a matter of executing: # yum install php-ldap Anyway:  Here is the example.  It's farily well commented so should be a simple matter to make work in your own environment. <?php // example.php // // David Latham @ 2010 // david-latham.blogspot.com // // This code cannot be executed on the same server as AD is installed on!!! // // Active Directory has an Organizational Unit of "_Test_Users" with 3 users loaded // into it. // user1 | User One // user2 | User Two // ldapbind | ldap bind // // execute with php -q example.php // credentials to test $user='user2@example.local';...

An excellent PHP script to handle time difference

I am working on a project that involves displaying the time difference between a start and end time on a website. The following script is lifted directly from: http://aidanlister.com/2004/04/making-time-periods-readable/ /** * A function for making time periods readable * * @author Aidan Lister * @version 2.0.0 * @link http://aidanlister.com/2004/04/making-time-periods-readable/ * @param int number of seconds elapsed * @param string which time periods to display * @param bool whether to show zero time periods */ function time_duration($seconds, $use = null, $zeros = false) { // Define time periods $periods = array ( 'years' => 31556926, 'Months' => 2629743, 'weeks' => 604800, 'days' => 86400, 'hours' => 3600, 'minutes' => 60, 'seconds' => 1 ); // Break into peri...

osCommerce & Register Globals

What happens when your web host finally get's around to upgrading to php5 and MySQL 5? Here is what happened to me in order: 1. Rejoice because finally your website is hosted according to industry standards. 2. Panic because you are unprepared. 3. Worked through the night to get the website updated. In order to migrate an osCommerce website from php4 to php5 there is really only one thing you need to worry about and that's a little "feature" in php called, Register Globals. Register Globals makes every variable contained in the URL, POST, SESSION and ENVIRONMENT directly available in every script. What this means is that with register globals turned on, you can write a webform that posts a variable to a script and that script can refer to the variable in the POST by name. For example: <?php /* ** Example script to show what happens when register globals is turned on. ** ** A form will submit POST data to this website as follows: ** String $_POST['name'];...