Page 1 of 1

Problem with cookies

Posted: Tue Dec 02, 2008 1:32 am
by kalpesh
hi i am trying to insert cookie in my application.

Code: Select all

 
 <script language="javascript" type="text/javascript">
function Citychange()
        {
   var city = document.getElementById('cityId').value;
   window.location.href="http://www.example.com/Live/indexcity.php?City=" + city;
    }
    </script>
 
<select name="city" id="cityId" class="city_texbox" onchange="javascript&#058;Citychange(this.value)">
                                      <option value="" selected="selected">Mumbai</option>
                                      <option value="" selected="selected">New York</option>
                                     <option value="" selected="selected">London</option>
                                 </select>
 
 
In above code when i select city the page displayed is indexcity.php
which works fine.
But in indexcity.php displays blank page.
indexcity.php code is following.

Code: Select all

 
  $city=$_GET['City'];
if(isset($_GET ['City']))
     {
 
           if(!isset($_COOKIE['City']))
           {
            setcookie ("City", $_GET['City'],time()+3600,"/Live");
            }
            
     }
 
 
 if (isset($_COOKIE['City'])) {
    echo $_COOKIE['City'] ;
}
 
It works fine in localhost. but in shared web hosting it displays blank page and no cookie is set.
Please help me.
Thanks in advance.

Re: Problem with cookies

Posted: Tue Dec 02, 2008 2:17 am
by requinix
Look at the options in your <select>. None of them have a value. Thus $_GET[City] has no value and your code doesn't do anything.