duandiao3961 2010-07-07 01:02
浏览 50
已采纳

我的网站主机在网址末尾添加了?PHPSESSID = fgh2h45 ...

I'm using iPage.com host. In order to use PHP sessions in their host I need to add session_save_path('/home/users/web/.../cgi-bin/tmp'); at the start of each page (in my case only index.php because everything goes trough index.php first).

Now, they automatically add the session id to the end of every URL requested like this: website.com/movies/details/?PHPSESSID=4s54kjhdl...

I think this is causing problems and can affect google indexing and SEO..

How to prevent this?

  • 写回答

3条回答 默认 最新

  • doutan5337 2010-07-07 01:06
    关注

    Your "host" isn't causing the issue, PHP is appending this data. Specifically, PHP is configured to append the PHPSESSID variable to the URL to allow PHP to track the session. It's possible to change the relevant setting using ini_set prior to calling session_start, or more permanently by updating the php.ini file (though since you're hosted this last option is probably out). This is a list of the available runtime settings for sessions in PHP.

    While you can control whether or not the value is appended to the end of your URLs, it's required to track the sessions. Alternatively you can configure PHP to use cookies to track sessions, but requiring cookies to track sessions may break your application for users who reject cookies.

    In short, you can control the session ID to make it a little prettier (by renaming PHPSESSID to something more amenable or making the value less cryptic) but unless you want to use cookies to maintain the session, you're stuck with this "garbage" on your URL. If you only use cookies some users may not be able to maintain the session.

    To enable cookie based session handling you can execute either:

    // stop PHP from automatically embedding PHPSESSID on local URLs
    ini_set('session.use_trans_sid', false);
    

    or

    // only use cookies (no url based sessions)
    ini_set('session.use_only_cookies', true);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?