Tech blog

PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Saturday, 30 August 2014

Iphone Push Notification using PHP

No comments :
In previous article we have learned android gcm notification using php but now we will see iphone notification using php.




Here I have wonderful code for it as below:



<?php
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', 
    $err, 
    $errstr, 
    60, 
    STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, 
    $ctx);

//if (!$fp)
//exit("Failed to connect amarnew: $err $errstr" . PHP_EOL);

//echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
    'badge' => +1,
    'alert' => $message,
    'sound' => 'default'
);

$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered amar'.$message. PHP_EOL;

// Close the connection to the server
fclose($fp);
?>

Notification to android apps using PHP

No comments :
WE have created website but also created application for our website.here i have created small code for sending notification thru CURL to android apps using php.First try to create your google application on google developers and make android notification ON.

After completing above steps,you will get an application access key for your code.just paste that in your code.and get registration id from an android developer so that u will able to send notification to that device.




Code:

<?php

// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );


$registrationIds = array( $_GET['id'] );

// prep the bundle
$msg = array
(
    'message' => 'first push notification message',
'title' => 'test title',
'subtitle' => 'subtitle',
'tickerText' => 'ticker',
'vibrate' => 1,
'sound' => 1
);

$message_array = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);

$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $message_array ) );
$result = curl_exec($ch );
curl_close( $ch );

echo $result;
?>

You will get notification as output of this code.This is known as Android GCM notification from PHP.



Sunday, 17 August 2014

Getting Video Thumbnails in PHP using ffmpeg

No comments :
Developers always create awesome codes by knowing language deeply.He can create ideas to make new innovative system.In PHP,same thing happens.As you all know extensions of php.ffmpeg is one of popular extension of php to take images from video.

Now,you can create images of your video.The video can be mp4,wmv,mkv etc..But here some lines are different.I have created code for windows system and with ffmpeg.exe

Download ffmpeg.exe for windows and paste following code in your editor.




Code:
<?php

$ffmpeg = 'ffmpeg.exe';

//video dir
$video = 'song.mp4';

//where to save the image
$image = 'image.jpg';

//interval
$interval = 5;

//image size
$size = '320x240';

//ffmpeg command
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";       
$return = `$cmd`;
?>

if you want to define directory you can define it  with "/".



Creating Facebook Apps

No comments :
Now a days,Facebook has socialized a lot.People want to advertise everything on social sites.Facebook Application is main interface to interact with Facebook functionality.To login,to post data on Facebook wall we need to create Facebook application.

Here are few steps which will help you to create Facebook Application:

Step-1:-

Go to https://developers.facebook.com/
Step-2:-

Go to Apps tab at top and click "create an app" button.
Finally you will get popup following page:

Step-3:-

Fill all above data and click on create app.Fill security text and go ahead.


Finally you are ready with Facebook application.

Thursday, 14 August 2014

Creating Twitter Apps

No comments :
Today I will tell you about how to create twitter application in your account

Step-1:
go to twitter application site:

http://dev.twitter.com/



Step-2:

Log-in to site with your username and password

Step-3:

Go to Below page and click on create new app button

When you click on this button the following page will open.Enter Application name,Application Description,website url and call back url.Check "Yes,I agree" box.

Now, click on create new app button below.

Congratulations!!Your application has been created.


Tuesday, 5 August 2014

How To Read Text Files using PHP

No comments :
I have posted tutorials for creating and posting of data.But here is good code and easy way in php to read text files which is stored in folder.In last post, I have posted code for making text file and directory.We will read data of same file.As assumed in code,files are same but contents in text file may be different.



Check out code for the same as follow:

<?php
$newdir='RuchiS';
echo  readfile($newdir.'/' ."newfile.txt");
?>


The above codee show one line which is reason for execution or say function names readfile.
 readfile is function in php which helps to read text file. 


Create Directory and text File using PHP

No comments :

We have been regularly in use of making directory using windows. and also text file.




Here is code which will help u to make folder and text files using php script.

<?php
$newdir='RuchiS';
$thisdir = getcwd();
echo "The Current Directory is ".$thisdir;
if(mkdir($thisdir . '/' . $newdir, 0777))
{
    $myfile = fopen($newdir.'/' ."newfile.txt", "w") or die("Unable to open file!");
    $txt = "Ruchi\n";
    fwrite($myfile, $txt);
    $txt = "Sanghvi\n";
    fwrite($myfile, $txt);
    fclose($myfile);
echo 'Directory has been created successfully...';
}
else
{
echo 'Failed to create directory...';
}
?>


The first line of code will be name of directory which you want to create in short,name of directory.Second line is for pointing current directory which u will create.

Here if condition will check wheather directory is made or not.and 777 will give write permission to folder.
under if condition text file will be created with fopen function.which will be in write mode.

In that text we can write text like Ruchi and Sanghvi. and fwrite function will write text into it.