开发者

.htaccess and cookie php

In my htaccess file, to convert the URL like http://au.youpon?area=Melbourne TO http://au.youpon/Melbourne. Have written the code in .htaccess file as

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?area=$1 [L]

That is working , in which the URL and city in jquery select box is working fine.

  1. In the index.php file, i am using the cookie concept (where if the user closes the browser, will load with the last city selected.

Scenario 1: If i selected "Melbourne", url will be like this "http://au.youpon/Melbourne" an in the cookie "CookieArea" Melbourne will be stored, and when i close the browser and open again displays "Melbourne", from the cookie variable, in a jquery box.) cookie is working, In this scenario.

Scenario 2: If i moves/navigate from index.php->file2.php->back to index.php, here it fails, and loads invalid data in place of city name, in the same jquery box, it means the cookie value is overwritten with invalid data.

(In place of city name displays like 'img/common/img/figure_quick_filter_01.png' or etc).

here is the cookie preferences code for storing the last selected city name.

In index.php :

if($_COOKIE['CookieArea']=="Select City"){
$cookieArea = '';
}else{  
$cookieArea = $_COOKIE['CookieArea'];
$co开发者_如何学运维okieCountry = $_COOKIE['CookieCountry'];
}
...
...
...
...
//[AT THE EOF, STORING THE CITY NAME AND COUNTRY]
setcookie("CookieArea", $area ,time()+(3600*24),'/');
setcookie("CookieCountry", $_SESSION['COUNTRYNAME'] ,time()+(3600*24),'/');

I am not sure, what is going wrong, either .htaccess or cookie code. Please help me, will be thank full to you all.

Can send more detail if required.


This is just a guess, but perhaps you're trying to send data through a GET parameter (query string) such as http://au.youpon/Melbourne?something=something. This will be cleared by your rewrite rule. To fix this, add QSA, which will glue together the old query string with the new one so you get both.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?area=$1 [QSA,L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜