Does not want to see PHPSESSID in the url. How can be done
this ?

Answers were Sorted based on User's Feedback



Does not want to see PHPSESSID in the url. How can be done this ?..

Answer / prantik gautam

1) Make the form method from 'get' to 'post'

2) If the form method is 'get' then keep the session id in
an extra session variable and call ob_start() for buffering.

eg :

ob_start();
session_start();
$sid=session_id(); //for different sesion id for each session
$_SESSION['sid']=$sid;

Is This Answer Correct ?    1 Yes 0 No

Does not want to see PHPSESSID in the url. How can be done this ?..

Answer / pankajbisane

1. In your config.php file, put the following code:

<?php

ini_set('session.use_trans_sid', 0);

ini_set(‘session.use_only_cookies’, 1);

?>

This will tell the server to overrule its current insecure
and SEO-unfriendly settings. Unfortunately, most shared
hosting companies don’t allow these modifications using
ini_set. Another method can be used.

2. In your .htaccess file, use the code below:

php_flag session.use_trans_sid off

php_flag session.use_only_cookies on

Place this file in the webroot of your website. It will have
the same result as method 1.

This should do the trick of preventing any ?PHPSESSID to any
new content. But, what to do if you already have webpages
listed in the search-engines with the ?PHPSESSID attached?
Use one of the solutions below:

1. Add the following code to the .htaccess file:

<IfModule mod_rewrite.c>

RewriteEngine On

#remove PHPSESSID

RewriteCond %{QUERY_STRING} PHPSESSID=.*$

RewriteRule .* %{REQUEST_URI}? [R=301,L]

</IfModule>

In order for this to work, the hosting company must have
their PHP compiled with mod_rewrite. If this isn’t the case,
another solution would work similarly

2. Add this code to your config.php file (retrieved from:
http://www.joostdevalk.nl/how-to-get-rid-of-phpsessid-in-the-url-and-redirect/)

<?php

if (isset($_GET['PHPSESSID']))

{

$requesturi =
preg_replace('/?PHPSESSID=[^&]+/',"",$_SERVER['REQUEST_URI']);

$requesturi = preg_replace('/&PHPSESSID=[^&]+/',"",$requesturi);

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://".$_SERVER['HTTP_HOST'].$requesturi);

exit;

}

?>

Is This Answer Correct ?    1 Yes 1 No

Does not want to see PHPSESSID in the url. How can be done this ?..

Answer / srikanth koka

1. In your config.php file, put the following code:

<?php

ini_set('session.use_trans_sid', 0);

ini_set(‘session.use_only_cookies’, 1);

?>

This will tell the server to overrule its current insecure
and SEO-unfriendly settings. Unfortunately, most shared
hosting companies don’t allow these modifications using
ini_set. Another method can be used.

2. In your .htaccess file, use the code below:

php_flag session.use_trans_sid off

php_flag session.use_only_cookies on

Place this file in the webroot of your website. It will have
the same result as method 1.

This should do the trick of preventing any ?PHPSESSID to any
new content. But, what to do if you already have webpages
listed in the search-engines with the ?PHPSESSID attached?
Use one of the solutions below:

1. Add the following code to the .htaccess file:

<IfModule mod_rewrite.c>

RewriteEngine On

#remove PHPSESSID

RewriteCond %{QUERY_STRING} PHPSESSID=.*$

RewriteRule .* %{REQUEST_URI}? [R=301,L]

</IfModule>

In order for this to work, the hosting company must have
their PHP compiled with mod_rewrite. If this isn’t the case,
another solution would work similarly

2. Add this code to your config.php file (retrieved from:
http://www.joostdevalk.nl/how-to-get-rid-of-phpsessid-in-the-url-and-redirect/)

<?php

if (isset($_GET['PHPSESSID']))

{

$requesturi =
preg_replace('/?PHPSESSID=[^&]+/',"",$_SERVER['REQUEST_URI']);

$requesturi = preg_replace('/&PHPSESSID=[^&]+/',"",$requesturi);

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://".$_SERVER['HTTP_HOST'].$requesturi);

exit;

}

?>

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

How can we get second of the current time using date function?

2 Answers   FD, IBM,


What is array function in javascript?

0 Answers  


What is memcache?

0 Answers  


What is the difference between myisam and innodb?

0 Answers  


Which php framework is fastest?

0 Answers  






Who developed php?

0 Answers  


How to create an array in php?

0 Answers  


What is the use of htmlspecialchars in php?

0 Answers  


Steps for the payment gateway processing?

0 Answers  


How to connect SMTP server in php. I want to edit that in mantiss bug tracking tool. If anyone worked on mantiss software or in php, please give answer . I need to modify that in mantiss software.

1 Answers   HCL, UHG,


What is env in laravel?

0 Answers  


What does $_cookie means?

0 Answers  


Categories