Top Questions

  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Jan 11, 2018

    A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

    Note: The setcookie() function must appear BEFORE the <html> tag.
    public function add_cookies($name,$value="",$time=3600) {
    	$this->load->helper('cookie');
    	if($value=="") {
    		return json_decode(get_cookie($name),true);
    	}
    	$val=$value;
    	if($val!="") {
    		$search1=get_cookie($name);
    		if($search1!="") {
    			$search1=json_decode($search1,true);
    			if(!in_array($val, $search1)) {
    				$search1[]=$val;
    				$cookie= array(
    				       'name'   => $name,
    				       'value'  => json_encode($search1),
    				       'expire' => $time,
    				   );
    				set_cookie($cookie);
    			}
    		} else {
    			$value=array();
    			$value[]=$val;
    			$cookie= array(
    			       'name'   => $name,
    			       'value'  => json_encode($value),
    			       'expire' => $time,
    			   );
    			set_cookie($cookie);
    		}
    	}
    	return json_decode(get_cookie($name),true);
    }
     

Add Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.