我的网络主机添加 ?PHPSESSID=fgh2h45... 到 URL 的末尾 [英] My web host is adding ?PHPSESSID=fgh2h45... to the end of the URL

查看:14
本文介绍了我的网络主机添加 ?PHPSESSID=fgh2h45... 到 URL 的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 iPage.com 主机.为了在他们的主机中使用 PHP 会话,我需要在每个页面的开头添加 session_save_path('/home/users/web/.../cgi-bin/tmp');我的情况只有 index.php,因为一切都首先通过 index.php).

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).

现在,他们会自动将会话 ID 添加到每个请求的 URL 的末尾,如下所示:website.com/movies/details/?PHPSESSID=4s54kjhdl...

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?

推荐答案

问题不是您的主机"造成的,PHP 正在附加此数据.具体来说,PHP 被配置为将 PHPSESSID 变量附加到 URL 以允许 PHP 跟踪会话.可以在调用 session_start 之前使用 ini_set 更改相关设置,或者通过更新 php.ini 文件来更永久地更改相关设置(尽管由于您是托管的,因此最后一个选项可能是出去).这是 PHP 会话的可用运行时设置列表.

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.

虽然您可以控制是否将值附加到网址的末尾,但需要跟踪会话.或者,您可以将 PHP 配置为使用 cookie 来跟踪会话,但要求 cookie 来跟踪会话可能会因拒绝 cookie 的用户而中断您的应用程序.

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.

简而言之,您可以控制会话 ID 以使其更漂亮(通过将 PHPSESSID 重命名为更适合的名称或使值不那么神秘),但除非您想使用 cookie 来维护会话,否则您会陷入困境你的 URL 上的这个垃圾".如果您使用 cookie,一些用户可能无法维持会话.

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.

要启用基于 cookie 的会话处理,您可以执行以下任一操作:

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);

// only use cookies (no url based sessions)
ini_set('session.use_only_cookies', true);

这篇关于我的网络主机添加 ?PHPSESSID=fgh2h45... 到 URL 的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆