Friday, February 2, 2018

how to see xml preview in browser php

xml preview view in browser

$xml = new DOMDocument('1.0', 'UTF-8');
                $xml->preserveWhiteSpace = false;
                $xml->formatOutput = true;
                $xml_data = $xml->createElement("DATA");
 $xml_row = $xml->createElement("ROW","test");
                                        $xml_data->appendChild( $xml_row );
 $str = $xml->saveXML();
                $str = "
".htmlspecialchars($str)."
";


xml not allowed character list

public function xmlEscape($string) {
        return str_replace(array('&', '<', '>', '\'', '"'), array('&', '<', '>', ''', '"'), $string);
    }


xml add html data in value
$xml_sub_col = $xml->createElement("ITEM");
$xml_sub_col->appendChild($xml->createCDATASection( "test"));

add attrubute in xml
$xml_sub_col->setAttribute("id",$arrValSubCol[0]);

Monday, November 23, 2015

Simulate an Incoming Call in Android Emulator

Android Studio

menu -> tools -> Android -> Android Device Monitor

open window dialog

select Emulator Control

Telephony Actions

In coming number :  1234567890
Voice radio button select
And call button press




Wednesday, July 8, 2015

Add Virtual host for nodejs in apache

Open apache virtual conf file


    ServerName www.yourdomain.com
    #ProxyPass / http://192.168.1.102:3000/ connectiontimeout=5 timeout=30  # optional timeout settings

    ProxyRequests off

   
        Order deny,allow
        Allow from all
   


   
        ProxyPass http://localhost:3000/
        ProxyPassReverse http://localhost:3000/
   

Virtualhost run in Genymotion

Open oracle virtual machine

Open file preferences

Click on left panel network

Open tab host only network

Right click on vboxnet0
Open dhcp server

Server address 192.168.1.110
Lower address bound 192.168.1.101
Upper address bound 192.168.1.119

Add host entry in android device

emulator -avd myAvdNameHere -partition-size 128  
adb remount  
adb pull /system/etc/hosts c:\temp  
add your virtual host entry and 
adb push c:\temp\hosts /system/etc

Tuesday, February 10, 2015

How to install MySQL Server 5.6 on CentOS 7 / RHEL 7

 
Remove mariadb
 
yum remove mariadb-server
yum remove mariadb-libs
 
step to install
 
yum install wget
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

rpm -ivh mysql-community-release-el7-5.noarch.rpm

[root@localhost ~]# ls -1 /etc/yum.repos.d/mysql-community* /etc/yum.repos.d/mysql-community.repo /etc/yum.repos.d/mysql-community-source.repo [root@localhost ~]#

Installing MySQL Server

 
yum install mysql-server


To start MySQL Service, run command

systemctl start mysqld

To stop MySQL Service, run command
systemctl stop mysqld

To restart MySQL Service, run command
systemctl restart mysqld


To get status of MySQL Service, run command
systemctl status mysqld
 

Reset MySQL root password

mysql -u root You will see mysql prompt like this mysql> . Use the below given commands to reset root’s password.
mysql> use mysql; 
mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root'; 
 mysql> flush privileges; 
 mysql> quit
     

Monday, October 13, 2014

hiphop with nginx and php 5.5 with opcache

hiphop with nginx is 2 time faster than php with appche
and
php-opcache is better than php-apc

I install hiphop with nginx in fedora 20 and centos 6.5

sh file run when system boot

add sh file in /etc/init.d/ directory

Tuesday, July 29, 2014

How to disable Selinux

The contents of my /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX=permissive
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
 
 
$ selinuxenabled && echo enabled || echo disabled enabled 

$ sestatus 
 

 

how to enable samba service

https://ask.fedoraproject.org/en/question/40353/how-to-enable-samba-share-for-a-specific-directory-fedora-20/

# useradd joe
# passwd joe

 or
adduser joe
 
smbpasswd -a joe


[accounts]
comment = Accounts data directory
path = /data/accounts
valid users = vivek raj joe
public = no
writable = yes
 
 # service smb restart
 

A note about adding users on Samba version 4.x

 
# /usr/local/samba/bin/samba-tool user add USERNAME-HERE
  

 # samba-tool user add USERNAME-HERE

Thursday, October 17, 2013

installed Xdebug on a Fedora 17 OS

I installed Xdebug on a Fedora 17 OS in order to use it with netbeans 7.3.1 It took me some time so I share with you how did I managed to have it working:
Install Xdebug:
sudo yum install php-pecl-xdebug
Add this lines to php.ini at the end of the file:
sudo vi /etc/php.ini
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Add the same lines to xdebug.ini file:
sudo vi /etc/php-zts.d/xdebug.ini
xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000
Allow port for Xdebug
sudo semanage port -a -t http_port_t -p tcp 9000
Now find your netbeans.conf file in your system:
sudo find / -name netbeans.conf
Now, open up the file and add the text "-J-Dorg.netbeans.modules.php.dbgp.level=400" in netbeans_default_options so that the line looks somewhat like this:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dnetbeans.logger.console=true -J-ea -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true -J-Dnetbeans.extbrowser.manual_chrome_plugin_install=yes -J-Dorg.netbeans.modules.php.dbgp.level=400"
Restart both NetBeans IDE and apache:
sudo service httpd restart
if not working then use

SQLSTATE[HY000]: General error: 1 Can't create/write to file '/tmp

You messed up with /tmp permissions. To fix:
chown root:root /tmp (root:root is mysql username and password which you used)
chmod 1777 /tmp 
/etc/init.d/mysqld restart (mysqld service restart)

Tuesday, September 10, 2013

[SOLVED] How to fix filesystem error - Fedora

/dev/mapper/volgroup-lv_root contains a filesystem with errors checks forced

run below command

# /dev/mapper/volgroup-lv_root
# fsck -f  /dev/mapper/volgroup-lv_root

Thursday, September 5, 2013

MySql backup with php script

<?php

    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($database_name,$link);

    $tableName  = '(select * from table_name where date(created_at) = "2013-09-04")';
  //$tableName = 'table_name';
    $backupFile = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'backup.sql';

    $query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";

    $result = mysql_query($query);

    echo "backup complete";

    mysql_close($link);
    $link = null;

?>

Restore table script

<?php
 

    $link = mysql_connect($host,$user,$pass);
     mysql_select_db($database_name,$link);

    $tableName  = 'table_name';
    $backupFile = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'backup.sql';

    $query      = "LOAD DATA INFILE '$backupFile' INTO TABLE $tableName";
    $result = mysql_query($query);

    echo "backup restore complete";

    mysql_close($link);
    $link = null;

?>

Monday, August 12, 2013

X-Debug in php 5.4.17


I installed Xdebug on a Fedora 17 OS in order to use it with netbeans 7.3.1 It took me some time so I share with you how did I managed to have it working:

Install Xdebug:

sudo yum install php-pecl-xdebug

Add this lines to php.ini at the end of the file:

sudo vi /etc/php.ini

zend_extension=/usr/lib64/php/modules/xdebug.so

xdebug.remote_enable=1

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_host=127.0.0.1

xdebug.remote_port=9000

Add the same lines to xdebug.ini file:

sudo vi /etc/php-zts.d/xdebug.ini


xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000

Allow port for Xdebug

sudo semanage port -a -t http_port_t -p tcp 9000

Now find your netbeans.conf file in your system:

sudo find / -name netbeans.conf


Now, open up the file and add the text "-J-Dorg.netbeans.modules.php.dbgp.level=400" in netbeans_default_options so that the line looks somewhat like this:


netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dnetbeans.logger.console=true -J-ea -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true -J-Dnetbeans.extbrowser.manual_chrome_plugin_install=yes -J-Dorg.netbeans.modules.php.dbgp.level=400"


Restart both NetBeans IDE and apache:

sudo service httpd restart

if not working then use

xdebug.remote_host=127.0.0.1 to ip address of computer

Saturday, March 23, 2013

how to install mongo db

Install mongo db step in centos/fedora

first check your os (32/64)
uname -m

Create a /etc/yum.repos.d/10gen.rep

open file and add bellow line in file and save the file (64bit os)
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1

open file and add bellow line in file and save the file (62bit os)
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
enabled=1

~]# yum install mongo-10gen mongo-10gen-server

~]# service mongo db start

~]# chkconfig --levels 235 mongod on

// step for install php mongo drive

~]# yum install php-devel git httpd

~]# export PHP_AUTOCONF=/usr/bin/autoconf

~]# export PHP_AUTOHEADER=/usr/bin/autoheader

~]# wget http://pecl.php.net/get/mongo-1.0.9.tgz

~]# tar -xzf mongo-1.0.9.tgz

~]# cd mongo-1.0.9

~]# phpize

~]# ./configure

~]# make install

~]# cd /etc/php.d

~]# vi mongo.ini

add bellow line in mongo.ini
extension=mongo.so

~]# service httpd restart

//test mongo db in prompt
//strat mongo
~]# mongo

//databse test use
>use test;

>doc = {"hello": "world", "php": "is alive!" };
>db.phptest.save(doc);
>db.phptest.findOne();

Example in php

<?php
$connection = new Mongo();
$db = $connection->test;
$collection = $db->phptest;

$obj = $collection->findOne();
echo "Hello " . $obj["hello"] . "!";

echo "Show result as an array:";
echo "<pre>";
print_r($obj);
echo "</pre>";

echo "Show result as JSON:";
echo "<pre>";
echo json_encode($obj);
echo "</pre>";


?>

install rockmongo for web view

download from rockmongo.com/downloads

extract file in web directory

create virtualhost


Friday, February 8, 2013

सरफ़रोशी की तमन्ना (Sarfaroshi ki Tamanna)

सरफ़रोशी की तमन्ना (Sarfaroshi ki Tamanna)

सरफ़रोशी की तमन्ना अब हमारे दिल में है
देखना है ज़ोर कितना बाज़ू-ए-क़ातिल में है

ऐ वतन, करता नहीं क्यूँ दूसरी कुछ बातचीत,
देखता हूँ मैं जिसे वो चुप तेरी महफ़िल में है
ऐ शहीद-ए-मुल्क-ओ-मिल्लत, मैं तेरे ऊपर निसार,
अब तेरी हिम्मत का चरचा ग़ैर की महफ़िल में है
सरफ़रोशी की तमन्ना अब हमारे दिल में है

वक़्त आने पर बता देंगे तुझे, ए आसमान,
हम अभी से क्या बताएँ क्या हमारे दिल में है
खेँच कर लाई है सब को क़त्ल होने की उमीद,
आशिकों का आज जमघट कूचा-ए-क़ातिल में है
सरफ़रोशी की तमन्ना अब हमारे दिल में है

है लिए हथियार दुश्मन ताक में बैठा उधर,
और हम तैयार हैं सीना लिए अपना इधर.
ख़ून से खेलेंगे होली अगर वतन मुश्क़िल में है
सरफ़रोशी की तमन्ना अब हमारे दिल में है

हाथ, जिन में है जूनून, कटते नही तलवार से,
सर जो उठ जाते हैं वो झुकते नहीं ललकार से.
और भड़केगा जो शोला सा हमारे दिल में है,
सरफ़रोशी की तमन्ना अब हमारे दिल में है

हम तो घर से ही थे निकले बाँधकर सर पर कफ़न,
जाँ हथेली पर लिए लो बढ चले हैं ये कदम.
ज़िंदगी तो अपनी मॆहमाँ मौत की महफ़िल में है
सरफ़रोशी की तमन्ना अब हमारे दिल में है

यूँ खड़ा मक़्तल में क़ातिल कह रहा है बार-बार,
क्या तमन्ना-ए-शहादत भी किसी के दिल में है?
दिल में तूफ़ानों की टोली और नसों में इन्कलाब,
होश दुश्मन के उड़ा देंगे हमें रोको न आज.
दूर रह पाए जो हमसे दम कहाँ मंज़िल में है,
सरफ़रोशी की तमन्ना अब हमारे दिल में है

वो जिस्म भी क्या जिस्म है जिसमे न हो ख़ून-ए-जुनून
क्या लड़े तूफ़ान से जो कश्ती-ए-साहिल में है
सरफ़रोशी की तमन्ना अब हमारे दिल में है
देखना है ज़ोर कितना बाज़ू-ए-क़ातिल में

---------------------------------------------------------------------
- By Ram Prasad Bismil


सरफरोशी की तमन्ना अब हमारे दिल में है,
देखना है जोर कितना बाजुए कातिल में है ।
करता नहीं क्यों दुसरा कुछ बातचीत,
देखता हूँ मैं जिसे वो चुप तेरी महफिल मैं है ।
रहबर राहे मौहब्बत रह न जाना राह में
लज्जत-ऐ-सेहरा नवर्दी दूरिये-मंजिल में है ।
यों खड़ा मौकतल में कातिल कह रहा है बार-बार
क्या तमन्ना-ए-शहादत भी किसी के दिल में है ।
ऐ शहीदे-मुल्को-मिल्लत मैं तेरे ऊपर निसार
अब तेरी हिम्मत का चर्चा ग़ैर की महफिल में है ।
वक्त आने दे बता देंगे तुझे ऐ आसमां,
हम अभी से क्या बतायें क्या हमारे दिल में है ।
खींच कर लाई है सब को कत्ल होने की उम्मींद,
आशिकों का जमघट आज कूंचे-ऐ-कातिल में है ।
सरफरोशी की तमन्ना अब हमारे दिल में है,
देखना है जोर कितना बाजुए कातिल में है ।
__
रहबर - Guide
लज्जत - tasteful
नवर्दी - Battle
मौकतल - Place Where Executions Take Place, Place of Killing
मिल्लत - Nation, faith
-------------------------------------------------------------------------------------

 'Rang De Basanti'. Here it goes -- though remember these lines are not part of the original poem written by 'Ram Prasad Bismil'.

है लिये हथियार दुश्मन ताक मे बैठा उधर
और हम तैय्यार हैं सीना लिये अपना इधर
खून से खेलेंगे होली गर वतन मुश्किल में है
सरफरोशी की तमन्ना अब हमारे दिल में है
हाथ जिनमें हो जुनून कटते नही तलवार से
सर जो उठ जाते हैं वो झुकते नहीं ललकार से
और भडकेगा जो शोला सा हमारे दिल में है
सरफरोशी की तमन्ना अब हमारे दिल में है
हम तो घर से निकले ही थे बांधकर सर पे कफ़न
जान हथेली में लिये लो बढ चले हैं ये कदम
जिंदगी तो अपनी मेहमान मौत की महफ़िल मैं है
सरफरोशी की तमन्ना अब हमारे दिल में है
दिल मे तूफानों की टोली और नसों में इन्कलाब
होश दुश्मन के उडा देंगे हमे रोको न आज
दूर रह पाये जो हमसे दम कहाँ मंजिल मे है
सरफरोशी की तमन्ना अब हमारे दिल में है

Monday, January 21, 2013

Reading a Remote File Using PHP

To read a remote file from php you have at least four options :
1. Use fopen()
2. Use file_get_contents()
3. CURL
4. Make your own function using php's socket functions.
First i need to warn you about something. You can only use fopen() and file_get_contents() when fopen wrappers is enabled. This parameter is specified in the php.ini file and cannot be changed at run time using ini_set(), To know whether you can use these two or not you can use the following code to check the value of fopen wrapper seting.
if (ini_get('allow_url_fopen') == '1') {
   // use fopen() or file_get_contents()
} else {
   // use curl or your custom function
}

1 . Using fopen()

If you use fopen() to read a remote file the process is as simple as reading from a local file. The only difference is that you will specify the URL instead of the file name. Take a look at the example below :
// make sure the remote file is successfully opened before doing anything else
if ($fp = fopen('http://www.google.com/', 'r')) {
   $content = '';
   // keep reading until there's nothing left
   while ($line = fread($fp, 1024)) {
      $content .= $line;
   }
   // do something with the content here
   // ...
} else {
   // an error occured when trying to open the specified url
}
Now, the code above use fread() function in the while loop to read up to 1024 bytes of data in a single loop. That code can also be written like this :
// make sure the remote file is successfully opened before doing anything else
if ($fp = fopen('http://www.google.com/', 'r')) {
   $content = '';
   // keep reading until there's nothing left
   while ($line = fgets($fp, 1024)) {
      $content .= $line;
   }
   // do something with the content here
   // ...
} else {
   // an error occured when trying to open the specified url
}
instead of fread() we use fgets() which reads one line of data up to 1024 bytes. The first code is much more preferable than the second though. Just imagine if the remote file's size is 50 kilobytes and consists of 300 lines. Using the first code will cause the loop to be executed about fifty times but using the second the loop will be executed three hundred times.
If you consider the cost to call a function plus the time required to make 300 requests compared to just 5 then clearly the first one is the winner.

2. Using file_get_contents()

This is my favorite way of reading a remote file because it is very simple. Just call this function and specify a url as the parameter. But make sure you remember to check the return value first to determine if it return an error before processing the result
$content = file_get_contents('http://www.google.com/');
if ($content !== false) {
   // do something with the content
} else {
   // an error happened
}

3. CURL

Unlike the two methods above using CURL cannot be said as straigthforward. Although this library is very useful to connect and communicate with may different protocols ( not just http ) it requires more effort to learn. And another problem is that not all web host have this library in their php installation. So we better make sure to check if the library is installed before trying to use it.
Here is a basic example on fetching a remote file
// make sure curl is installed
if (function_exists('curl_init')) {
   // initialize a new curl resource
   $ch = curl_init();

   // set the url to fetch
   curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');

   // don't give me the headers just the content
   curl_setopt($ch, CURLOPT_HEADER, 0);

   // return the value instead of printing the response to browser
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   // use a user agent to mimic a browser
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');

   $content = curl_exec($ch);

   // remember to always close the session and free all resources
   curl_close($ch);
} else {
   // curl library is not installed so we better use something else
}
In some cases using CURL is faster than using file_get_contents() or fopen(). This is because CURL handles compression protocols by default ( for example gzip ). Many sites, big and small, use gzip compression to compress their web pages in order to save bandwidth. This site, for example, also use gzip compression which cut the bandwidth used into half. So if you're the type who just can't wait CURL will fit you most.


4. Custom functions

In the worst case your server will have fopen wrappers disabled and don't have CURL library installed. In this sad situation you just have to make your own way.
Our function shall be named getRemoteFile() which takes only one parameter, the url for the remote file. The skeleton for this function is shown below
function getRemoteFile($url)
{
   // 1. get the host name and url path

   // 2. connect to the remote server

   // 3. send the necessary headers to get the file

   // 4. retrieve the response from the remote server

   // 5. strip the headers

   // 6. return the file content
}
To extract the host name and url path from the given url we'll use parse_url() function. When given a url this function will spit out the followings :
  • scheme
  • host
  • port
  • user
  • pass
  • path
  • query
  • fragment
For example, if the url is http://www.php-mysql-tutorial.com/somepage.php then parse_url() will return :
Array
(
    [scheme] => http
    [host] => www.php-mysql-tutorial.com
    [path] => /somepage.php
)
and if the url is http://myusername:mypassword@www.php-mysql-tutorial.com/somepage.php?q=whatsthis#ouch then parse_url() will return this :
Array
(
    [scheme] => http
    [host] => www.php-mysql-tutorial.com
    [user] => myusername
    [pass] => mypassword
    [path] => /somepage.php
    [query] => q=whatsthis
    [fragment] => ouch
)
For our new function we only care about the host, port, path and query.
To establish a connection to a remote server we use fsockopen(). This function requires five arguments, the hostname, port number, a reference for error number, a reference for the error message and timeout
function getRemoteFile($url)
{
   // get the host name and url path
   $parsedUrl = parse_url($url);
   $host = $parsedUrl['host'];
   if (isset($parsedUrl['path'])) {
      $path = $parsedUrl['path'];
   } else {
      // the url is pointing to the host like http://www.mysite.com
      $path = '/';
   }

   if (isset($parsedUrl['query'])) {
      $path .= '?' . $parsedUrl['query'];
   }

   if (isset($parsedUrl['port'])) {
      $port = $parsedUrl['port'];
   } else {
      // most sites use port 80
      $port = '80';
   }

   $timeout = 10;
   $response = '';    // connect to the remote server
   $fp = @fsockopen($host, $port, $errno, $errstr, $timeout );
   if( !$fp ) {
      echo "Cannot retrieve $url";
   } else {
      // send the necessary headers to get the file
      fputs($fp, "GET $path HTTP/1.0\r\n" .
                 "Host: $host\r\n" .
                 "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3\r\n" .
                 "Accept: */*\r\n" .
                 "Accept-Language: en-us,en;q=0.5\r\n" .
                 "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" .
                 "Keep-Alive: 300\r\n" .
                 "Connection: keep-alive\r\n" .
                 "Referer: http://$host\r\n\r\n");
      // retrieve the response from the remote server
      while ( $line = fread( $fp, 4096 ) ) {
         $response .= $line;
      }
      fclose( $fp );

      // strip the headers
      $pos      = strpos($response, "\r\n\r\n");
      $response = substr($response, $pos + 4);
   }
   // return the file content
   return $response;
}
The code above sends nine lines of headers but only the first two is mandatory. So even if you send only these
fputs($fp, "GET $path HTTP/1.0\r\n" .
           "Host: $host\r\n\r\n");
the function will likely be working correctly. Not always though. Since the file is stored in a remote server It really up to that server to reply to your request or not. Some people code their page to block any request without the proper referer header. Some will only accept a specific user agent. Other will require cookies set in the header.
If you want to see what headers should be sent to successfully fetch a specific remote file try using firefox plus live http headers plugin. It's really a useful little tool

Friday, July 13, 2012

how to remove unwanted toolbar in firefox

In firefox address bar

type:- about:config

search in filter and remove or modify value of unwanted toolbar in firefox

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; ...