0

我的链接是这样的:http://example.com/events.php?slug=xyz

其中 [slug] 字段是从数据库中导入的。events.php我页面的起始行是:

$slug = $_GET['slug'];
$url="events.php?slug=".$slug."/";
....
....

我的注销功能:

if(isset($_GET['logout']))
{
    $_SESSION = array();
    session_destroy();
    header('Location: ' . $url);
    exit;
}


<?php if(isset($_SESSION['id'])){?>
    <a href="?logout" ><button>Log Out</button></a>
<?php }?>

但点击后logout "http://example.com/events.php?slug=/"会显示。

php在页面开头的整个脚本是:

<?php
define('INCLUDE_CHECK',true);

require_once('13/functions/db.php');
    $slug = $_GET['slug'];
    $url="events.php?slug=".$slug."/";
    $result = mysql_query("SELECT * FROM event WHERE slug='".$slug."'");
    if ($result == true){
        $row=mysql_fetch_assoc($result);
        $id=$row['id'];
        if($id>=13 && $id<=40 && $id!=17){//some checks.
            $var=1;
            $name=$row['name'];
        }
        else {
            $var=0;
            $name="404";
        }
    }

session_name('fewiui');
session_set_cookie_params(3*7*24*60*60);
session_start();

if(isset($_GET['logout']))
{
    $_SESSION = array();
    session_destroy();
    header('Location: ' . $url);
    exit;
}


$sess_uid = $_SESSION['id'];
$sess_email = $_SESSION['email'];
$sess_name = $_SESSION['name'];
if(isset($_POST['submit'])&&$_POST['submit']=='Register')
    require_once('13/functions/eventlogin.php');    
?>

其他一切(如登录等)都有效。我在哪里做错了?我是php的新手。

4

1 回答 1

0
 <a href="?slug=<?php echo $slug; ?>&logout" ><button>Log Out</button></a>
于 2013-02-06T16:57:31.177 回答