I have been trying to post a message and image on a page feed. I keep getting the error message
(#1) An error occured while creating the share.
This only happens if someone else tries to post. If I, the owner of the page tries to post it is successful.
So my question is: Is it possible to post to another users page feed?
I have done a lot of research into this but I cant seem to find a plausible solution.
Here is the code I am using to post the message:
<?php
class Photo_contest_helper extends Facebook
{
private $_key = '***********';
private $_secret = '***************';
private $_page_id = '387228561388254';
public $fb_login_url;
public $fb_logout_url;
public $image_id;
public function init()
{
$this->connect();
$image_id = $this->save_image();
if( !!$image_id ) {
$this->image_id = $image_id;
$this->push_to_facebook( $image_id );
}
}
public function save_image()
{
$image_id = NULL;
if ( !!$_POST[ "image" ] || !!$_FILES ) {
$image_id = Image_helper::save_one( $_POST[ "image" ] );
}
return $image_id;
}
public function push_to_facebook( $image_id )
{
$access_token = $this->get_page_access_token();
$this->publish_photo( $access_token );
}
public function connect()
{
parent::__Construct( array( 'appId' => $this->_key, 'secret' => $this->_secret ) );
$user = $this->getUser();
if( !$user ) {
$this->fb_login_url = $this->getLoginUrl( array( 'scope' => 'manage_pages,publish_actions,publish_stream,status_update' ) );
}
else {
$this->fb_logout_url = $this->getLogoutUrl( array( 'next' => 'http://stormtest.co.uk/' . DIRECTORY . "home/logout" ) );
}
}
public function get_page_access_token()
{
$accounts = $this->api( '/me/accounts', 'get' );
$access_token = NULL;
foreach ( $accounts[ 'data' ] as $account ) {
if ( $account[ 'id' ] == $this->_page_id ) {
$access_token = $account[ 'access_token' ];
}
}
return $access_token;
}
public function publish_photo( $access_token = "" )
{
$params = array( 'message' => 'Competition entry',
'link' => 'http://stormtest.co.uk/' . DIRECTORY . '_admin/assets/uploads/images/' . $this->get_image(),
'caption' => 'This is my competition entry',
'picture' => 'http://stormtest.co.uk/' . DIRECTORY . '_admin/assets/uploads/images/' . $this->get_image() );
if( !!$access_token ) {
$params[ 'access_token' ] = $access_token;
}
try {
$this->api( '/' . $this->_page_id . '/feed', 'post', $params );
}
catch( FacebookApiException $e ) {
die( print_r( $e ) );
}
}
public function get_image()
{
$image_model = new Image_model();
$image_model->find( $this->image_id );
return $image_model->attributes[ 'imgname' ];
}
}
?>
Thanks in advance.
You should use the JavaScript SDK to share content to the page. Posting to others' walls via the API has been disabled:
FB.ui( {
method: 'feed',
to: '387228561388254',
name: "Facebook API: Tracking Shares using the JavaScript SDK",
link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, callback );
Use the to field in the above code to set the page_id, and change the other attributes accordingly (but don't change method).
Related
Previously i was used http server for my linkedin login. Now I changed https server for my entire site. But now i cannot show login details after changed that. Here i post my function, In this fuction i also changed https. But yet not i show the details. I use this function in codeigniter.
public function login(){
$client_id = $this->config->item('linkedin_app_id');
$redirect_uri = base_url().'linkedinLogin';
if (isset($_GET['error'])) {
echo $_GET['error'] . ': ' . $_GET['error_description'];
} elseif (isset($_GET['code'])) {
$this->loginAccessToken();
$user = $this->login_fetch('GET', '/v1/people/~:(id,firstName,lastName,email-address,picture-url)');//get name
$email = $user->emailAddress;
$user_name = $user->firstName;
$last_name = $user->lastName;
$social_id = $user->id;
$profile_image_url = 'user-thumb.png';
echo "<pre>";print_r($user); die;
if($email != '')
{
$googleLoginCheck = $this->user_model->googleLoginCheck($email);
if($googleLoginCheck > 0)
{
//echo "login";
$getGoogleLoginDetails = $this->user_model->google_user_login_details($email);
//echo "<pre>";print_r($getGoogleLoginDetails);die;
$userdata = array(
'fc_session_user_id' => $getGoogleLoginDetails['id'],
'session_user_email' => $getGoogleLoginDetails['email']
);
//echo "<pre>";print_r($userdata);die;
$this->session->set_userdata($userdata);
if($this->data['login_succ_msg'] != '')
$lg_err_msg = $this->data['login_succ_msg'];
else
$lg_err_msg = 'You are Logged In ...';
$this->setErrorMessage('success',$lg_err_msg);
redirect(base_url());
}
else
{
$google_login_details = array('social_login_name'=>$user_name,'social_login_unique_id'=>$social_id,'screen_name'=>$user_name,'social_image_name'=>'','social_email_name'=>$email,'loginUserType'=>'google');
//echo "<pre>";print_r($google_login_details);die;
//echo "redirect to registration page";
$social_login_name = $user_name;
$this->session->set_userdata($google_login_details);
$firstname = $user_name;
$lastname = $last_name;
$orgPass = time();
$pwd = md5($orgPass);
$Confirmpwd = $orgPass;
$username = $user_name;
$condition = array ('email' => $email);
$duplicateMail = $this->user_model->get_all_details ( USERS, $condition );
$expireddate = date ( 'Y-m-d', strtotime ( '+15 days' ) );
$dataArr = array('firstname'=>$firstname,'lastname'=>$lastname,'user_name'=>$firstname,'group'=>'User','image'=>$profile_image_url,'email'=>$email,'password'=>$pwd,'status'=>'Active','expired_date'=>$expireddate,'is_verified'=>'No','loginUserType'=>'linkedin','google'=>'Yes','created'=>date('Y-m-d H:i:s'));
$this->user_model->simple_insert(USERS,$dataArr);
$lstID = $this->db->insert_id();
//echo $this->db->last_query(); die;
$userdata = array (
'quick_user_name' => $firstname,
'quick_user_email' => $email,
'fc_session_user_id' => $lstID,
'session_user_email' => $email
);
$this->session->set_userdata ( $userdata );
$this->setErrorMessage('success','Registered & Login Successfully');
redirect(base_url());
}
}
else
{
redirect('');
}
}else {
header("Location:https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=$client_id&redirect_uri=$redirect_uri&state=987654321&scope=r_basicprofile%20r_emailaddress%20w_share");
}
}
public function loginAccessToken() {
$params = array(
'grant_type' => 'authorization_code',
'client_id' => $this->config->item('linkedin_app_id'),
'client_secret' => $this->config->item('linkedin_app_key'),
'code' => $_GET['code'],
'redirect_uri' => base_url().'linkedinLogin'
);
// Access Token request
$url = 'https://www.linkedin.com/uas/oauth2/accessToken?' . http_build_query($params);
// Tell streams to make a POST request
$context = stream_context_create(
array('https' =>
array('method' => 'POST',
)
)
);
// Retrieve access token information
$response = file_get_contents($url, false, $context);
// Native PHP object, please
$token = json_decode($response);
// Store access token and expiration time
$_SESSION['access_token'] = $token->access_token; // guard this!
$_SESSION['expires_in'] = $token->expires_in; // relative time (in seconds)
$_SESSION['expires_at'] = time() + $_SESSION['expires_in']; // absolute time
return true;
}
public function login_fetch($method, $resource, $body = '') {
$opts = array(
'https' => array(
'method' => $method,
'header' => "Authorization: Bearer " .
$_SESSION['access_token'] . "\r\n" .
"x-li-format: json\r\n"
)
);
$url = 'https://api.linkedin.com' . $resource;
// if (count($params)) {
// $url .= '?' . http_build_query($params);
// }
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);
return json_decode($response);
}
Here look the login() fuction. I print the user details. But i got empty window only
echo "<pre>";print_r($user); die;
But when i use http, i got the user details. Can help me anyone?
Just implemented facebook login on my test site, and it seems too simple to be true?
I am using these two from GitHub
https://github.com/Lusitanian/PHPoAuthLib
https://github.com/artdarek/oauth-4-laravel
To implement this I added a button:
{{ link_to_action('UserController#loginWithFacebook', 'Facebook Login in', $parameters = array(), $attributes = array('class' => 'btn btn-primary fb-login-btn')); }}
And then modifiying the example login method to authorise the user after success:
public function loginWithFacebook() {
$code = Input::get( 'code' );
$fb = OAuth::consumer( 'Facebook' );
if ( !empty( $code ) ) {
$token = $fb->requestAccessToken( $code );
$result = json_decode( $fb->request( '/me' ), true );
// ADDED SECTION
$newUser = User::create(
array(
'email' => $result['email']
)
);
$user = User::find($newUser->id);
Auth::login($user);
return Redirect::to('/');
} else {
$url = $fb->getAuthorizationUri();
return Redirect::to( (string)$url );
}
}
This works, which has surprised me... is this really all it takes?
The question im asking really is would this be the way its intended to be used? The response is used to create a user, then log them in after with their ID.
I only use their email, since they only need to login using the facebook button. In the future I could prompt them to add a password so they don't always have to use facebook login but the basics of this is correct?
// get data from input
$code = Input::get( 'code' );
// get fb service
$fb = OAuth::consumer( 'Facebook' );
// check if code is valid
// if code is provided get user data and sign in
if ( !empty( $code ) ) {
// This was a callback request from facebook, get the token
$token = $fb->requestAccessToken( $code );
// Send a request with it
$result = json_decode($fb->request( '/me?fields=id,name,first_name,last_name,email,photos' ), true);
$message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name']. $result['email'];
//echo $message. "<br/>";
//Var_dump
//display whole array().
//echo('http://graph.facebook.com/'.$result['id'].'/picture?type=large<br>');
//dd($result);
$user = \User::where("email",$result['email'])->first();
if($user!=NULL){
$userxx = Sentry::findUserByLogin($result['email']);
Sentry::login($userxx, false);
return Redirect::to('Beşiktaş');
}
else
{
$k=str_random(8);
$user = Sentry::register(array(
'activated' => 1,
'facebook' => 1,
'password' => $k,
'email' => $result['email'],
'first_name' =>$result['first_name'],
'last_name' => $result['last_name'] ,
'avatar' => 'http://graph.facebook.com/'.$result['id'].'/picture?type=large',
));
Sentry::login($user, false);
return Redirect::to('Beşiktaş');
}
}
// if not ask for permission first
else {
// get fb authorization
$url = $fb->getAuthorizationUri();
// return to facebook login url
return Redirect::to( (string)$url );
}
Hello there I am working on a website which has redirect loop
Here is the file the issue with facebook integration has issue...it redirects..
https://www.whyshopping.com/login.php?login=facebook
It contains the following code:
<?php
include_once( 'generic.class.php' );
class Jigowatt_integration extends Generic {
public $enabledMethods;
public static $socialLogin = array(
'twitter',
'facebook',
'google',
'yahoo'
);
private $result;
private $num;
function __construct() {
$this->enabledMethods = $this->findEnabledMethods();
/**
* Twitter.
*/
if (in_array('twitter', $this->enabledMethods)) {
require 'integration/twitter/EpiCurl.php';
require 'integration/twitter/EpiOAuth.php';
require 'integration/twitter/EpiTwitter.php';
}
/**
* Facebook.
*/
if (in_array('facebook', $this->enabledMethods)) {
require 'integration/facebook/facebook.php';
}
/**
* OpenID Networks (Google, Yahoo).
*/
if (in_array('google', $this->enabledMethods) || in_array('yahoo', $this->enabledMethods)) {
include_once( 'integration/openid/openid.php' );
}
/** If the user is logged out, we'll treat them as a guest. */
if (empty($_SESSION['jigowatt']['user_id'])) {
//$this->guestLogin();
return false;
}
$this->retrieveInfo();
/** User wants to unlink his account from a social method. */
if ( !empty($_GET['unlink']) ) {
$this->unlink($_GET['unlink']);
$this->retrieveInfo();
}
if ( !empty($_GET['link']) ) {
$this->link_account($_GET['link']);
$this->retrieveInfo();
}
}
/** Check if this method is already in linked or not. */
public function isUsed($method) {
return !empty($this->result[$method]);
}
private function retrieveInfo() {
$params = array( ':user_id' => $_SESSION['jigowatt']['user_id'] );
$sql = "SELECT * FROM `login_integration` WHERE `user_id` = :user_id;";
$stmt = parent::query($sql, $params);
$this->num = $stmt->rowCount();
$this->result = $stmt->fetch(PDO::FETCH_ASSOC);
}
private function findEnabledMethods() {
$methods = array();
foreach ( self::$socialLogin as $method )
if ( parent::getOption('integration-'.$method.'-enable') )
$methods[] = $method;
return $methods;
}
public function link_account($link, $login = false) {
/** Make sure we only allow specific social links. */
if ( !in_array($link, self::$socialLogin) )
return false;
/** Check if user is already linked. */
if ( !empty($this->result[$link]) ) {
parent::displayMessage(sprintf('<div class="alert alert-warning">' . _('Your account is already linked with %s!') . '</div>', ucwords($link)), false);
return false;
}
/** See if the link was successful. */
if ( !empty($_SESSION['jigowatt'][$link]) ) {
if (!$login) $this->connect($link);
return false;
}
switch ($link) :
case 'facebook' :
header( 'Location: ' . $this->facebook_url() );
exit();
break;
case 'twitter' :
header( 'Location: ' . $this->twitter_url() );
exit();
break;
default :
$this->openid_url($link);
break;
endswitch;
}
private function connect($link) {
if ( empty($_SESSION['jigowatt']['user_id']) )
return false;
$params = array(
':user_id' => $_SESSION['jigowatt']['user_id'],
':session_link' => $_SESSION['jigowatt'][$link]
);
if ($this->num < 1)
$sql = "INSERT INTO `login_integration` (`user_id`, `$link`) VALUES (:user_id, :session_link);";
else
$sql = "UPDATE `login_integration` SET `$link` = :session_link WHERE `user_id` = :user_id;";
parent::query($sql, $params);
parent::displayMessage(sprintf('<div class="alert alert-success">%s</div>', _('Successfully linked with ' . ucwords($link))), false);
}
private function unlink($provider) {
if ( !in_array($provider, self::$socialLogin) )
return false;
if ( empty($this->result[$provider]) ) {
parent::displayMessage(sprintf('<div class="alert alert-warning">' . _('You are not yet linked with %s') . '</div>', ucwords($provider)), false);
return false;
}
$params = array( ':user_id' => $_SESSION['jigowatt']['user_id'] );
$sql = "UPDATE `login_integration` SET $provider = null WHERE `user_id` = :user_id;";
parent::query($sql, $params);
unset($_SESSION['jigowatt'][$provider]);
parent::displayMessage(sprintf('<div class="alert alert-success">' . _('Successfully unlinked from %s') . '</div>', ucwords($provider)), false);
}
private function openid_url($link) {
$providers = array(
'google' => 'https://www.googleapis.com/plus/v1/people/me/openIdConnect',
'yahoo' => 'https://me.yahoo.com',
'aol' => 'http://openid.aol.com/{username}',
'openid' => ''
);
if ( !empty($_GET['link']) || !empty($_GET['login']) )
$link = !empty($_GET['link']) ? $_GET['link'] : $_GET['login'];
try {
$openid = new LightOpenID(str_replace("www.","", $_SERVER['HTTP_HOST']));
if(!$openid->mode) {
if(!empty($link)) {
$openid->identity = $providers[$link];
$openid->returnUrl = str_replace("www.","", SITE_PATH) . basename($_SERVER['PHP_SELF']) . '?link=' . $link;
$openid->required = array('contact/email', 'namePerson/first', 'namePerson/last');
header('Location: ' . $openid->authUrl());
exit();
}
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
if ($openid->validate()) :
if( !empty($providers[$link]) ) :
$_SESSION['jigowatt'][$link] = $openid->identity;
$this->connect($link);
$_SESSION['jigowatt']['openIDMisc'] = $openid->getAttributes();
$_SESSION['jigowatt']['openIDMisc']['type'] = $link;
$_SESSION['jigowatt']['openIDMisc'][$link] = $openid->identity;
endif;
endif;
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
}
public function facebook_url() {
if( !empty($_SESSION['jigowatt']['facebook']) )
return false;
$facebook = new Facebook(array(
'appId' => parent::getOption('facebook-app-id'),
'secret' => parent::getOption('facebook-app-secret'),
));
$this->fbUser = $facebook->getUser();
if ($this->fbUser) :
$user_profile = $facebook->api('/me');
try {
$_SESSION['jigowatt']['facebookMisc'] = $user_profile;
$_SESSION['jigowatt']['facebook'] = $this->fbUser;
} catch (FacebookApiException $e) {
error_log($e);
$this->fbUser = null;
}
endif;
$params = array(
'redirect_uri' => str_replace("https://www.","", SITE_PATH) . basename($_SERVER['PHP_SELF']) . '?link=facebook',
'scope' => 'email'
);
return $this->fbUser ? '#' : $facebook->getLoginUrl($params);
}
public function twitter_url() {
if ( !empty($_SESSION['jigowatt']['twitter']) )
return false;
$consumer_key = parent::getOption('twitter-key');
$consumer_secret = parent::getOption('twitter-secret');
$this->twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
if( !empty($_GET['oauth_token']) ) {
$this->twitterObj->setToken($_GET['oauth_token']);
$token = $this->twitterObj->getAccessToken();
$this->twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
$twitterInfo = $this->twitterObj->get_accountVerify_credentials();
$twitterInfo = $twitterInfo->response;
$_SESSION['jigowatt']['twitter'] = $twitterInfo['id'];
$_SESSION['jigowatt']['twitterMisc']['username'] = $twitterInfo['screen_name'];
$_SESSION['jigowatt']['twitterMisc']['id'] = $twitterInfo['id'];
$_SESSION['jigowatt']['twitterMisc']['name'] = $twitterInfo['name'];
}
return !empty($_SESSION['jigowatt']['twitter']) ? '#' : $this->twitterObj->getAuthenticateUrl( null,array('oauth_callback' => str_replace("https://www.","", SITE_PATH) . basename($_SERVER['PHP_SELF']) . '?link=twitter' ));
}
}
$jigowatt_integration = new Jigowatt_integration();
i got the solution actually my .htaccess file had the issue & it worked
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^$ https://www.domain.com%{REQUEST_URI} [R,L]
I am trying to post on behalf of user. I have used tutorial given on this page: http://25labs.com/updated-post-to-multiple-facebook-pages-or-groups-efficiently-v2-0/ .
I could successfully perform authentication but could not post on behalf.
Here is the source code : https://github.com/karimkhanp/fbPostOnBehalf
Testing can be done here: http://ec2-54-186-110-98.us-west-2.compute.amazonaws.com/fb/
Does any one experienced this?
I'm not familiar with the batch process that the tutorial is using but below is a code sample that posts to a Facebook group
<?php
# same this file as
# test.php
include_once "src/facebook.php";
$config = array(
'appId' => "YOURAPPID",
'secret' => "YOURAPPSECRET",
'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
);
class PostToFacebook
{
private $facebook;
private $pages;
public function initialise($config){
$this->name = "Facebook";
// current necessary configs to set
// $config = array(
// 'appId' => FB_APP_ID,
// 'secret' => FB_APP_SECRET,
// 'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
// );
$this->facebook = new Facebook($config);
try{
// if user removes app authorization
$this->hasAccess = $this->has_permissions();
if($this->hasAccess){
$this->groups = $this->getGroupData();
}
}
catch(Exception $err){
}
}
public function postMessageToGroup($message, $groupid){
$messageResponse = array(
'STATUS' => 0
);
$fbMessageObj = array(
"message" => strip_tags($message),
);
try
{
$user_page_post = $this->facebook->api("/$groupid/feed", 'POST', $fbMessageObj);
if($user_page_post && !empty($user_page_post['id'])){
$messageResponse['STATUS'] = 200;
$messageData = array(
'id' => $user_page_post['id'],
'link' => 'http://facebook.com/' . $user_page_post['id'],
);
$messageResponse['data'] = $messageData;
}
else{
$messageResponse['STATUS'] = 302;
}
}
catch(Exception $err){
$messageResponse['STATUS'] = 500;
$messageResponse['data'] = array($err);
}
return $messageResponse;
}
// TODO: should read a template somewhere
function show_login() {
$login_url = $this->facebook->getLoginUrl( array( 'scope' => implode(",",$this->permissions()) ));
return 'Login to Facebook and Grant Necessary Permissions';
}
// TODO: should read a template somewhere
public function toString()
{
if($this->hasAccess){
if($this->groups){
$msg = "";
$msg .= '<select name="group_id"><option value=""></option>';
foreach($this->groups as $group) {
$msg .= '<option value="' .
'' . urlencode($group['id']) .
'">' .
$group['name'] .
'</option>' .
'';
}
$msg .= '</select>';
return $msg;
}
else
return "No Groups";
}
else{
return $this->show_login();
}
}
function getGroupData(){
$raw = $this->facebook->api('/me/groups', 'GET');
$data = array();
if (null != $raw && array_key_exists('data', $raw))
return $raw['data'];
return null;
}
// check if current instance has access to facebook
function has_permissions() {
$user_id = #$this->facebook->getUser();
#print_r($user_id);
if($user_id == null) return false;
$permissions = $this->facebook->api("/me/permissions");
foreach($this->permissions() as $perm){
if( !array_key_exists($perm, $permissions['data'][0]) ) {
return false;
}
}
return true;
}
// permissins needed to post
function permissions(){
return array('manage_pages', 'user_groups');
}
}
$fb = new PostToFacebook();
$fb->initialise($config);
if(!$fb->has_permissions())
{
echo $fb->show_login();
}
else{
?>
<form method="post" action="test.php">
<textarea name='message'></textarea>
<?php echo $fb->toString(); ?>
<input type='submit'>
</form>
<?php
}
if(!empty($_POST)){
$response = $fb->postMessageToGroup($_POST['message'], $_POST['group_id']);
if($response['STATUS'] == 200)
print_r("<a href='" . $response['data']['link'] . "'>" . $response['data']['id'] ."</a>");
else
{
echo "ERROR!";
print_r($response);
}
}
?>
I created a Facebook page, added a new Tab with an application.
Now I want todo these steps:
See if User liked the page // Is Working
Ask for permissions to post a status // Isn't working
Finish.
This is the code which I use:
$permissions = array (
'email',
'user_status',
'publish_stream',
'status_update'
);
public function __construct($app_id, $secret, $perm)
{
$this->facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $secret,
'cookie' => true
));
$this->perm = $perm;
}
public function checkPermissions()
{
$allPerm = true;
$permissions = $this->facebook->api("/me/permissions");
foreach($this->perm as $value)
{
if(!array_key_exists($value, $permissions['data'][0]) ) {
$allPerm = false;
}
}
return $allPerm;
}
public function RequestPermissions()
{
header( "Location: " . $this->facebook->getLoginUrl($this->GenerateScope()) );
}
public function GenerateScope()
{
$scope = null;
$last_key = array_keys($this->perm);
$last_key = end($last_key);
foreach ($this->perm as $key => $value) {
if ($key == $last_key) {
$scope .= $value;
} else {
$scope .= $value . ',';
}
}
return array("scope" => $scope);
}
So, I check for the Permissions, if not all are set, I want to ask for them.
$this->facebook->getLoginUrl($this->GenerateScope()).
But when i display the link, or redirect to it, nothings (really nothing) happens?
Your tab application is operating within an iframe element on facebook.com. To redirect users to a different URL, you'll have to change the top most frame's location.
This is possible using JavaScript, so all you have to do is get your PHP code to echo out this JavaScript code -
$url = $facebook->getLoginUrl(...your_params...);
echo "<script language=javascript>";
echo "top.location.href ='".$url."';";
echo "</script>";
exit();
That will execute the redirect for your users.