Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

请教网站和论坛共享session的方法

[复制链接]
sanmusoft 发表于 2011-6-5 12:34:33 | 显示全部楼层 |阅读模式
我现在要做一个PHP的网站,想实现和discuz论坛同步登录,想请问一下,如何实现这个session共享啊.

就是在网站上检查如果登录了论坛了,就不用登录了,如果没有登录,就显示登录框,登录之后,还是回到网站这块.

谢谢.
sjzy365 发表于 2011-6-5 13:47:30 | 显示全部楼层
UC中心就是解决这个问题的吧
回复

使用道具 举报

 楼主| sanmusoft 发表于 2011-6-5 17:14:54 | 显示全部楼层
<?php
/**
* UCenter 应用程序开发 Example
*
* UCenter 简易应用程序,应用程序无数据库
* 使用到的接口函数:
* uc_authcode()        可选,借用用户中心的函数加解密 Cookie
* uc_pm_checknew()        可选,用于全局判断是否有新短消息,返回 $newpm 变量
*/

require ('./config.inc.php');
require ('./uc_client/client.php');


/**
* 获取当前用户的 UID 和 用户名
* Cookie 解密直接用 uc_authcode 函数,用户使用自己的函数
*/
if(!empty($_COOKIE['Example_auth'])) {
        list($Example_uid, $Example_username) = explode("\t", uc_authcode($_COOKIE['Example_auth'], 'DECODE'));
} else {
        $Example_uid = $Example_username = '';
}

/**
* 获取最新短消息
*/

/*$newpm = uc_pm_checknew($Example_uid);*/

/**
* 各个功能的 Example 代码
*/
switch(@$_GET['example']) {
        case 'login':
                //UCenter 用户登录的 Example 代码
                include 'code/login_nodb.php';
        break;
        case 'logout':
                //UCenter 用户退出的 Example 代码
                include 'code/logout.php';
        break;
        case 'register':
                //UCenter 用户注册的 Example 代码
                include 'code/register_nodb.php';
        break;
        case 'pmlist':
                //UCenter 未读短消息列表的 Example 代码
                include 'code/pmlist.php';
        break;
        case 'pmwin':
                //UCenter 短消息中心的 Example 代码
                include 'code/pmwin.php';
        break;
        case 'friend':
                //UCenter 好友的 Example 代码
                include 'code/friend.php';
        break;
        case 'avatar':
                //UCenter 设置头像的 Example 代码
                include 'code/avatar.php';
        break;
}

echo '<hr />';
if(!$Example_username) {
        //用户未登录
        echo '<a href="'.$_SERVER['PHP_SELF'].'?example=login">登录</a> ';
        echo '<a href="'.$_SERVER['PHP_SELF'].'?example=register">注册</a> ';
} else {
        //用户已登录
        echo '<script src="ucexample.js"></script><div id="append_parent"></div>';
        echo $Example_username.' <a href="'.$_SERVER['PHP_SELF'].'?example=logout">退出</a> ';
        echo ' <a href="'.$_SERVER['PHP_SELF'].'?example=pmlist">短消息列表</a> ';
        echo $newpm ? '<font color="red">New!('.$newpm.')</font> ' : NULL;
        echo '<a href="###" onclick="pmwin(\'open\')">进入短消息中心</a> ';
        echo ' <a href="'.$_SERVER['PHP_SELF'].'?example=friend">好友</a> ';
        echo ' <a href="'.$_SERVER['PHP_SELF'].'?example=avatar">头像</a> ';
}

?>

阅读了文档,但是这段代码一执行就报:

UCenter info: MySQL Query Error
SQL:SELECT value FROM [Table]vars WHERE name='noteexists2'
Error:No database selected
Errno:1046

这个错,
回复

使用道具 举报

 楼主| sanmusoft 发表于 2011-6-5 17:41:58 | 显示全部楼层
妈呢个鬼哟,终于搞成功了.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-5-16 21:22 , Processed in 0.045628 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表