- Facebookでログインが出来るWebサービスの作り方を解説していきます。
##サンプルコード
| create table users ( | |
| id int not null auto_increment primary key, | |
| facebook_user_id varchar(30) unique, | |
| facebook_name varchar(255), | |
| facebook_picture varchar(255), | |
| facebook_access_token varchar(255), | |
| created datetime, | |
| modified datetime | |
| ); |
| <?php | |
| define('DB_HOST', 'localhost'); | |
| define('DB_USER', 'root'); | |
| define('DB_PASSWORD', '(設定したパスワード)'); | |
| define('DB_NAME', 'fb_connect_php'); | |
| define('APP_ID','(取得したAPP_ID)'); | |
| define('APP_SECRET','(取得したAPP_SECRET)'); |
| <?php | |
| require_once('config.php'); | |
| session_start(); | |
| $_SESSION = array(); | |
| if (isset($_COOKIE[session_name()])) { | |
| setcookie(session_name(), '', time()-86400, '/fb_connect_php/'); |
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Login</title> | |
| </head> | |
| <body> | |
| <h1>Login</h1> | |
| <p><a href="redirect.php">Facebookでログイン</a></p> | |
| </body> |
| <?php | |
| require_once('config.php'); | |
| session_start(); | |
| if (empty($_GET['code'])) { | |
| // 認証の準備 | |
| $_SESSION['state'] = sha1(uniqid(mt_rand(), true)); |
| <?php | |
| require_once('config.php'); | |
| session_start(); | |
| function h($s) { | |
| return htmlspecialchars($s, ENT_QUOTES, "UTF-8"); | |
| } |
| <?php | |
| define('DB_HOST', 'localhost'); | |
| define('DB_USER', 'dbuser'); | |
| define('DB_PASSWORD', '(設定したパスワード)'); | |
| define('DB_NAME', 'dotinstall_fb_connect_php'); | |
| define('APP_ID','(取得したAPP_ID)'); | |
| define('APP_SECRET','(取得したAPP_SECRET)'); |
##サンプルコード
##ユーザー管理の基本 必要な知識 ###言語リファレンス
| <?php | |
| require_once('config.php'); | |
| require_once('functions.php'); | |
| session_start(); | |
| if (empty($_SESSION['me'])) { | |
| header('Location: '.SITE_URL.'login.php'); | |
| exit; |