2011
Nov
02
wordpree 会员登入使用到 Cookie 功能,而且前后台的 Cookie读的路径不太一样,所以登入后每个路径都要设 Cookie。
- wordpress 的登入的cookie资料,必需设定以下路径
/ 主目录
/wp前端目录
/wp/wp-admin 后台目录
/wp/wp-content/plugin 外挂目录
- cookie名称长得像这样:wordpress_logged_in_XXXXXXXXXX
登入整合
- 需要的include的档案
Example
- require_once(/wp/wp-includes/class-phpass.php');
- require_once(/wp/wp-includes/cache.php');
- 比对登入帐密是否正确
Example
- function user_password($username,$password=false){
- //抓 user的资料
- $u=*get user Data
- $wp_hasher = new PasswordHash(8, TRUE);
- $check = $wp_hasher->CheckPassword($password, $u[0]['user_pass']);
- return $check;
- }
- 储存user 的 cookie
Example
- //设定 cookie的名称
- define('COOKIEHASH', md5 ( wp_options的 siteurl );
- define('AUTH_COOKIE','wordpress_logged_in_'.COOKIEHASH);
- //设定$current_user
- $user=getUserID(); //抓user ID;
- wp_set_current_user($user);
- //设定cookie路径
- $cookie = AUTH_COOKIE;
- $s =
- setcookie($cookie,$s,$time,COOKIEPATH, COOKIE_DOMAIN, '', true);
- setcookie($cookie,$s,$time,SITECOOKIEPATH, COOKIE_DOMAIN, '', true);
- setcookie($cookie,$s,$time,ADMIN_COOKIE_PATH, COOKIE_DOMAIN, '', true);
- setcookie($cookie,$s,$time,PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, '', true);
wordpress POST 被阻挡
在wordpress中,自已的post form 常常被wordpress阻挡
解决方式:建立一个新的post.php档案
Example
- if ( !isset($wp_did_header) ) {
- $wp_did_header = true;
- require_once( dirname(__FILE__) . '/wp-load.php' );
- wp();
- require_once( ABSPATH . WPINC . '/template-loader.php' );
- }
- //导到目标档案
- require(TEMPLATEPATH.'/index.php');