Problem with cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kalpesh
Forum Commoner
Posts: 54
Joined: Sun Sep 21, 2008 5:04 am

Problem with cookies

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem with cookies

Post 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.
Post Reply