Monday, May 21, 2012

ssl on symfony

copy bellow file in symfony apps/lib forder

filename: sslFilter.class.php

<?php
/**
 * Description of sslFilter
 */
class sslFilter extends sfFilter
{
  /**
   * Execute filter
   *
   * @param FilterChain $filterChain The symfony filter chain
   */
  public function execute ($filterChain)
  {
    // Only execute this filter once
    if ($this->isFirstCall()) {
      // Array of modules/actions that require move to SSL
      $ssl_actions = sfConfig::get('app_ssl_secure_actions');

      if (empty($_SERVER['HTTPS']) && count($_POST) < 1) {

        // We're not using SSL and not POSTing data - check if we should be using SSL
        foreach ($ssl_actions as $action) {
          if ($this->getContext()->getModuleName() == $action['module'] && $this->getContext()->getActionName() == $action['action']) {
            $new_url = sprintf('https://%s%s', sfConfig::get('app_ssl_secure_host'), $_SERVER['REQUEST_URI']);
            header('Location: ' . $new_url);
            exit;
          }
        }

      } elseif (!empty($_SERVER['HTTPS']) && count($_POST) < 1) {

        // We're using SSL and not posting data
        $dont_redirect = false;
        foreach ($ssl_actions as $action) {
          if ($this->getContext()->getModuleName() == $action['module'] && $this->getContext()->getActionName() == $action['action']) {
            $dont_redirect = true;
          }
        }
        if ($dont_redirect == false) {
          // Redirect
          $new_url = sprintf('http://%s%s', sfConfig::get('app_ssl_insecure_host'), $_SERVER['REQUEST_URI']);
          header('Location: ' . $new_url);
          exit;
        }
      }
    }
    // Next filter
    $filterChain->execute();
  }
}
?>

in filter.yml file

rendering: ~
web_debug: ~
security:  ~

# generally, you will want to insert your own filters here
sslFilter:
  class:  sslFilter

cache:     ~
common:    ~
flash:     ~
execution: ~

app.yml file
# default values
all:
  ssl:
    insecure_host:    www.myhostname.com
    secure_host:      www.myhostname.com
    secure_actions:
      - { module: securemodule, action: secureaction }
      - { module: sslmodulename, action: sslactionname }

php odbc connection

php odbc in linux

yum install unixODBC

yum install php-odbc

in /etc/odbcinst.ini file

# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description     = ODBC for MySQL
Driver          = /usr/lib/libmyodbc5.so
Setup           = /usr/lib/libodbcmyS.so
Driver64        = /usr/lib64/libmyodbc5.so
Setup64         = /usr/lib64/libodbcmyS.so
FileUsage       = 1

edit /etc/odbc.ini


mysqlmyodbc = MySQL

[mysqlmyodbc]
Driver      = /usr/lib/libmyodbc5.so
Server      = localhost
Port        = 3306
User        = username
Password    = password
Database    = databasename
Option      = 3
Socket      = /var/run/mysqld/mysqld.sock


save the /etc/odbc.ini file

service httpd restart
service mysqld restart

test php file

<?php

$conn = odbc_connect("DRIVER={MySQL};Server=localhost;Database=databasename", "username", "password");
/* $sql = "SELECT 1 as test";
 $rs = odbc_exec($conn,$sql);
 odbc_fetch_row($rs);
 echo "\nTest\n—--\n" . odbc_result($rs,"test") . "\n";
 */

$sql = "SELECT * from table_name";
$result = odbc_exec($conn,$sql);
if($result)
{
    while($row = (odbc_fetch_array($result)))
    {
        foreach ($row as $k=>$v)
        {
            echo $k."=>".$v;
            echo "<br/>";
        }
    }
}
?>

how to see xml preview in browser php

xml preview view in browser $xml = new DOMDocument('1.0', 'UTF-8');                 $xml->preserveWhiteSpace = false; ...