drrhr20884 2012-03-21 04:06
浏览 50
已采纳

session_id不使用session_name

I am using the session_name to rename my session to lets says 'xxx'. Using this I am also able to start a session using session_start. I also able see the cookie being set in my browser.

//TO SET session

login.php

session_name('xxx');
session_start();

But the problem is that I am not able to retrieve the session id using the session_id call in an another script.

another.php

session_name('xxx');

$id = session_id();
echo $id // This is showing empty

var_dump($_COOKIE) // This is showing the cookie xxx with the session id 

if(!empty($id))
{
  //If he is already logged in, lets get his details
  session_start();
}

I know that I can go ahead and read the cookie to see if the session is set. But I was just curious to know why this is not working. Isn't the session_id function retrieve my session id after setting the session_name ?

We know the that session_start is going to open my existing session but on the other hand if at all there isn't session then it will start a new one. I don't want start a new session if it is not already started.

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • doushoubu5360 2012-03-21 04:10
    关注

    There will be no session_id before you start the session with session_start.
    session_name just sets the cookie/URL param name, it does not start a session.

    And yes, you need to start() the session on every single page you want to use it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据