Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--controller -->
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Welcome extends CI_Controller {
- public function __construct(){
- parent::__construct();
- // To use site_url and redirect on this controller.
- $this->load->helper('url');
- }
- public function login(){
- $this->load->library('facebook'); // Automatically picks appId and secret from config
- $user = $this->facebook->getUser();
- if ($user) {
- try {
- $data['user_profile'] = $this->facebook->api('/me');
- } catch (FacebookApiException $e) {
- $user = null;
- }
- }else {
- $this->facebook->destroySession();
- }
- if ($user) {
- $data['logout_url'] = site_url('welcome/logout'); // Logs off application
- } else {
- $data['login_url'] = $this->facebook->getLoginUrl(array(
- 'redirect_uri' => site_url('welcome/login'),
- 'scope' => array("email") // permissions here
- ));
- }
- $this->load->view('login',$data);
- }
- public function logout(){
- $this->load->library('facebook');
- $this->facebook->destroySession();
- redirect('welcome/login');
- }
- }
- <!--view--->
- <?php if (@$user_profile): // call var_dump($user_profile) to view all data ?>
- <img src="https://graph.facebook.com/<?=$user_profile['id']?>/picture?type=large" style="width: 140px; height: 140px;">
- <h2><?=$user_profile['name']?></h2>
- <!--emailnya gak ke tarik om--->
- <h2><?=$user_profile['email']?></h2>
- <!-- Create link logout -->
- <a href="<?= $logout_url ?>">Logout</a>
- <?php else: ?>
- <h2>Login with Facebook Using CodeIgniter</h2>
- <a href="<?= $login_url ?>">Login</a>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement