Skip to content

Instantly share code, notes, and snippets.

@leggetter
Created August 30, 2011 10:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leggetter/1180618 to your computer and use it in GitHub Desktop.
Save leggetter/1180618 to your computer and use it in GitHub Desktop.
Pusher PHP Auth example
<?php
// https://github.com/squeeks/Pusher-PHP
require('squeeks-Pusher-PHP-0defb40/lib/Pusher.php');
$key = 'APP_KEY';
$secret = 'APP_SECRET';
$app_id = 'APP_ID';
$pusher = new Pusher($key, $secret, $app_id);
$channel_name = $_POST['channel_name'];
if(!$channel_name) {
$channel_name = $_GET['channel_name'];
}
$socket_id = $_POST['socket_id'];
if(!$socket_id) {
$socket_id = $_GET['socket_id'];
}
$callback = $_POST['callback'];
if(!$callback) {
$callback = $_GET['callback'];
}
if(!$channel_name) {
exit("channel_name must be supplied");
}
if(!$socket_id) {
exit("socket_id must be supplied");
}
//echo("channel_name: " . $channel_name . " socket_id: " . $socket_id);
$auth = $pusher->socket_auth($channel_name, $socket_id);
if(!$callback) {
header('Content-Type: application/json');
echo($auth);
}
else {
$callback = str_replace('\\', '', $callback);
header('Content-Type: text/javascript');
echo("$callback($auth);");
}
?>
@kufupatel
Copy link

I am trying to implement pusher notification service, currently i am using public channel so notification is accessible to all..
Can you give me brief info on how can use private channel so notification can go to only particular person on my website..
and which thing I have to consider to identify unique person so notification goes to only him ???
I am new to socket programming so I have no more knowledge on this ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment