Welcome Guest, Not a member yet? Register   Sign In
URGENT - Changing a function to previously define a cookie - I’ll pay $5 for the one that helps me on this ASAP!
#1

[eluser]msfaria[/eluser]
Hi there!

I'm changing a CodeIgniter script that used to have a splash page where the user could choose its city and the script sent him / her to the corresponding city page - New York, for example. I removed that splash page and its code, sending the user directly to the main page ( $this->render('main'); at the end of the function), but I need to make it work by defining the cookie with a default city, so other parts of the script can work properly and people can continue to enter the city page ('.base_url().'page/city/'.$user_city_name, where $user_city_name would be new york, for example). How can I do this?

Here's the actual code:

Code:
function index()
    {
                $this->load->model('location_model');
                $this->load->helper('cookie');
                $cookie_city = get_cookie('user_city');
                $cookie_city_name = get_cookie('user_city_name');
                if(isset($cookie_city_name) && $cookie_city_name!=''){
                   // $city_name = $this->location_model->get_city_list(1,0,array('id'=>$cookie_city));
                   // $this->session->set_userdata('user_city_name',$city_name[0]['city_name']);
                   header('location:'.base_url().'page/city/'.$user_city_name);
                   exit;
                }
                $this->data['old_values'] = $this->session->userdata('user_values');
                $this->session->set_userdata('user_values', '' );
                if($this->input->post('sub')!='')
                {
                        $message    = '';
                        $arr_post = array();
                        $temp_arr = array_merge($arr_post, $_POST);
                        $this->session->set_userdata('user_values', $temp_arr );
            $this->session->set_userdata('user_messages', array());
                        if($message=='')
                        {
                                $city_id = htmlspecialchars($this->input->post('city_id'), ENT_QUOTES, 'utf-8');
                                $cookie = array(
                                           'name'   => 'user_city',
                                           'value'  => $city_id,
                                           'expire' => time()+(60*60*24*365),
                                           'domain' => '',
                                           'path'   => '/',
                                           'prefix' => '',
                                   );
                                set_cookie($cookie);
                                $city_name = $this->location_model->get_city_list(1,0,array('id'=>$city_id,));
                                $cookie = array(
                                           'name'   => 'user_city_name',
                                           'value'  => $city_name[0]['url'],
                                           'expire' => time()+(60*60*24*365),
                                           'domain' => '',
                                           'path'   => '/',
                                           'prefix' => '',
                                   );
                                set_cookie($cookie);
                                $this->session->set_userdata('user_values', '');
                                exit;
                        }
                          $this->session->set_userdata(array('message'=>$message,'message_type'=>'err'));
                }
                $this->add_js(array('common_js'));
                $this->render('main');
    }

Could anyone help me on this asap? I need to make it work today...
#2

[eluser]msfaria[/eluser]
Anyone?
#3

[eluser]msfaria[/eluser]
I’ll pay $5 for the one that helps me on this ASAP!
#4

[eluser]icomefromthenet[/eluser]
I see that you trying to create new cookies, why not just save the data into the default session, it will then persist between page requests, if for some reason the sessions are lost between page loads you might want look up forum for that issue.




Theme © iAndrew 2016 - Forum software by © MyBB