Free Android CakePHP GMaps Articles by Bali Web Design

February 13, 2012

How to enable and disable PHPSESSID

Filed under: php-tips-basic — admin @ 10:13 pm

For some case where the visitor cannot save cookie, we need to put it on the url. This is happen on some browser also that cannot save cookie, like i-mode in japan. It will be a big task to add PHPSESSID to all pages URL, so we can enable PHPSESSID using php script setting.

ini_set('session.use_cookies', 0);
ini_set('session.use_only_cookies', 0);
ini_set('session.use_trans_sid', 1);
ini_set('', 'PHPSESSID');
ini_set('url_rewriter.tags', 'a=href,area=href,frame=src,input=src,form=,fieldset=');

or add to php.ini

php_value session.use_cookies 0
php_value session.use_only_cookies 0
php_value session.use_trans_sid 1

And then for some reason also we need to disable PHPSESSID, for example to avoid duplicate content because off different session ID on the URL.

Here are how to disable PHPSESSID on URL

php_value session.use_only_cookies 1
php_value session.use_trans_sid 0

and to permanent redirect all previous link with PHPSESSID added to the url, use this php script

$actualurl= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$correcturl = '';
if ($correcturl != $actualurl) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $correcturl);

And then please check on google all URL that have PHPSESSID, get list of them and then make a page that linking to all URL that you want to permanently redirect. It is a bit hard the get rid after indexing by google, but we need to do that to remove all duplicate content.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment