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

Thursday, December 12, 2013

php: send xml in post request and read xml in post request

to send xml data in post request using curl:
<?php
        $XMLreq = '<?xml version="1.0" encoding="UTF-8"?>';
        $XMLreq = $XMLreq . '<!DOCTYPE svc_init SYSTEM "http://x.x.x.x/sample.DTD">';
        $XMLreq = $XMLreq . '<svc_init ver="1.0.0">';
        $XMLreq = $XMLreq . '<object>sample</object>';
        $XMLreq = $XMLreq . '</svc_init>';
        $URLreq = "http://x.x.x.x/XMLreceive.php";

        $ch = curl_init($URLreq);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $XMLreq);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);
        $output = curl_exec($ch);
        curl_close($ch);
        echo $output;
?>

to read xml data received in post request:
<?php
        if(isset($HTTP_RAW_POST_DATA))
        {
                echo $HTTP_RAW_POST_DATA;
        }
?>

Thursday, April 04, 2013

php: send email through gmail via mail

1. setup php and include mail:
this is how i did it on my linux box
# yum install php-pear
# pear install --alldeps Mail-1.2.0

2. to use mail in php:
// email settings
require_once "Mail.php";
$username = "<gmail email address here>@gmail.com";
$password = "<gmail email password here>";
$from = "<gmail email address here>@gmail.com";
$host = "ssl://smtp.gmail.com";
$port = "465";

$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);

$smtp = Mail::factory(
'smtp',
array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
)
);

$mail = $smtp->send($to, $headers, $message);

if(PEAR::isError($mail))
{
$resultstring = "email sending error: " . $mail->getMessage();
}
else
{
$resultstring = "email sent to $to";
}

Thursday, January 24, 2013

php: extract image coordinates via exif

configure php with '--enable-exif' 

extract coordinates from exif

<?php
        $file = $_GET['file'];
        $exif = exif_read_data($file, 0, true);
 
        if(!$exif || $exif['GPS']['GPSLongitude'] == '')
        {
                $response = '';
        }
        else
        {
                $long = $exif['GPS']['GPSLongitude'];
                list($num, $dec) = explode('/',$long[0]);
                $long_d = $num / $dec;
                list($num, $dec) = explode('/',$long[1]);
                $long_m = $num / $dec;
                list($num, $dec) = explode('/',$long[2]);
                $long_s = $num / $dec;
                $long_dec = $long_d + $long_m / 60 + $long_s / 3600;
 
                $lat = $exif['GPS']['GPSLatitude'];
                list($num, $dec) = explode('/',$lat[0]);
                $lat_d = $num / $dec;
                list($num, $dec) = explode('/',$lat[1]);
                $lat_m = $num / $dec;
                list($num, $dec) = explode('/',$lat[2]);
                $lat_s = $num / $dec;
                $lat_dec = $lat_d + $lat_m / 60 + $lat_s / 3600;
 
                $response = trim($long_dec . " " . $lat_dec);
        }
        echo $response;
?>

Thursday, August 02, 2012

mongodb: php driver installation

download and unzip mongodb-mongo-php-driver (i currently use mongodb-mongo-php-driver-1.2.10-158-ged35f95.zip)

# ./configure
# make
# makeinstall


add extension=mongo.so in your php.ini


make sure you have your php's extension_dir pointing to the right path where mongo.so is located

Monday, July 30, 2012

mapserver php: php_mapscript.so unable to load dynamic library

was able to experience this in two different scenarios

1.) got:
Warning: dl() [function.dl]: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/php_mapscript.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/php_mapscript.so: cannot open shared object file: No such file or directory


Fatal error: Call to undefined function ms_newMapObj()

make sure mapserv is compiled with --with-php=/usr/local/include/php

create directory /usr/local/lib/php/extensions/no-debug-non-zts-20060613
copy mapserver-5.0.3/mapscript/php3/php_mapscript.so to the directory above

to test, create a php test file then browse
<HTML>
<BODY>
<?php
  if (PHP_OS == "WINNT" || PHP_OS == "WIN32")
  {
    dl("php_mapscript.dll");
  }
  else
  {
    dl("php_mapscript.so");
  }
  phpinfo();
?>
</BODY>
</HTML>


2.) got:
Warning: dl() [function.dl]: Unable to load dynamic library './php_mapscript.so' - ./php_mapscript.so: cannot open shared object file: No such file or directory


Fatal error: Call to undefined function ms_newMapObj()

check your php.ini and make sure you point the extension_dir parameter to where your mapscript is located.
i have mine in apache's modules directory
extension_dir = "/usr/local/apache2/modules/"

Tuesday, February 28, 2012

linux: php basic installation with apache configuration

download a php source file and install
# ./configure
# make
# make install


copy php.ini-dist to /usr/local/lib/php.ini

edit your php.ini file and set the following:
extension_dir = "/usr/local/apache2/modules/" # this is my apache modules directory
include_path = "/usr/local/lib/php
extension=php_mysql.so

if you have pgsql add:
extension=php_pgsql.so

edit your /etc/ld.so.conf file and add the following:
/usr/local/lib
/usr/local/include

if you have pgsql add:
/usr/local/pgsql/lib

load ldconfig
# ldconfig -v

edit your apache httpd.conf configuration file
verify that the line below is not in comment:
LoadModule php5_module modules/libphp5.so
then add the following lines:
                -AddType application/x-httpd-php .php
                -AddType application/x-httpd-php-source .phps
                -AddType application/x-httpd-php .phtml

restart your apache server

create a test php file with the content below:
<?php phpinfo(); ?>
then test by browsing your test php file

sometimes it takes a while before php pages work after installation. give it a few minutes before testing

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...