Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Saturday, January 19, 2013

Active Directory Authentication for APACHE Web Server

For authenticating users against their Active Directory account in APACHE Web Server, you have to edit the /etc/apache2/httpd.conf .

Notes

  1. You should bind some other common AD account with LDAP
  2. Provide LDAP URL of you Domain Controller . Here I assume the Domain is DC.EXAMPLE.COM and IP of the Domain Controller is 192.168.40.1 .
  3. I am binding with another account guest@example.com . So give FQDN of this acount .
  4. You should enable the authnz_ldap module for apache.

Sunday, January 13, 2013

PHP-MySQLi Class

What is MySQLi

MySQLi (MySQL improved) is a driver used in PHP to access MySQL databases. PHP 5.5.0 deprecate the use of old mysql driver and it gives warning that old driver will be removed in the future versions. Also it recommends the use of MySQLi or PDO_MySQL extension.

PHP-MySQLi Class

https://github.com/ajillion/PHP-MySQLi-Database-Class/blob/master/MysqliDb.php provides a good PHP class for MySQLi, MySqliDb Class . Go get the code. Now import the Class into your project:

String to MySQL date format in PHP

String to Date in PHP

Sometimes when I export some MS Excel/ MS Access data to MySQL , It is required to convert some date in string to MySQL compatible date format. You can use DateTime class to convert the string to date in any format you want. The code is below.
function _mk_date($str)
{
 $temp = new DateTime($datestr);
 return date_format($temp, 'Y-m-d');
}

Saturday, April 17, 2010

PHP script for getting tweet updates

Here is the php script to get updates from a twitter account.

   $uname = "YourUserName";
   $url = "http://twitter.com/statuses/user_timeline/$uname.rss";
   $rss = @file_get_contents($url);

  if($rss)
  {
          $xml = @simplexml_load_string($rss);
          if($xml !== false)
           {
                 foreach($xml->channel->item as $tweet)
                  {
                       echo $tweet->pubDate."\n";
                       echo substr($tweet->description,10)."\n";
                   }
            }
           else
             {
                   echo "Error: RSS file not valid!";
             }
       }
       else
      {
          echo "Error: RSS file not found, Invalid username";
      }
?>