Q: Setting Cookie in PHP Form Submit? Here I have Situation to set the cookie after the form submitting into the same page.....
Here is the Code: 
<?php
require_once 'config.php';
$dbHandle = DBHandler::getInstance();
@session_start();
if($_POST['division'])
{
    $fromDiv =$_POST['division'];
    $divId =explode(',',$fromDiv);
    echo $divId[0].'~';
    echo $_COOKIE['preDiv'].'dfg'.'<br/>';
    setcookie("preDiv",$divId[0],time() + (10 * 365 * 24 * 60 * 60));
    $_SESSION['division'] = $divId[0];
}
$sql=$dbHandle->execQuery("SELECT * FROM master_division");
$division_str = '<option value="">--select--</option>';
while($fetch = $dbHandle->fetchObjectQuery($sql))
{
    $division = $fetch->division_id.','.$fetch->name;
    $division_str .= '<option value="'.$division.'">'.$fetch->name.'</option>';
}

echo $_COOKIE['preDiv'].'dfg'.'<br/>';
echo $_SESSION['division'];
?>
<!DOCTYPE html>
<html>
<body class="login" style="overflow: hidden;">

        <div class="login-box" style="position: absolute;z-index: 999;padding: 10px;width: 40%;min-height: 200px;margin-left:-20%;">
            <section class="portlet login-box-top" style="height:100%;">
                <header>
                    <h2 class="ac">CHOOSE DIVISION To MEDISMO CRM LOGIN</h2>
                </header>
                <section style="height:76%;">
                    <div id="popup_box" > <!-- OUR PopupBox DIV-->
                    <div id="group_comp" style="margin-top:15%;margin-left:20%;">
                    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" style="border:none;">
                    <label><b>Choose Division:</b></label>
                    <select id="division" name="division"><?php echo $division_str;?></select>
                    <input type="submit" id="ok" value="OK" />
                    </form>
                    </div>
                </div>
                </section>
            </section>
        </div>
</body>

</html>

Anyone suggest me what is wrong in it...

A: To give the cookie a lifetime read through the following documentation
http://php.net/manual/de/function.setcookie.php
in here you find in the described paramterlist
bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )

the value $expire which you need to provide with a TTL, e.g. time()+60*60*24*30 which would make the cookie valid for 30 days from now on!
If you want to have whatever you want to store available right away while outputting the html content, you should just put the $_COOKIE['whatever'] into a variable and use that

A: It's not possible to set cookies that never expire, but..
If you don't want a cookie to expire, then you might want to set it for 20 years.
if you want your cookies to be available on current HTTP request (after you set them), you can do this trick:
function cookieSet(array $data){
   foreach($data as $key => $value){

      $_COOKIE[$key] = $value; // <- to make them available on current HTTP request

      setcookie($key, $value, time() + strtotime('+20 years'));
   }
}


A: Issue solved Guys.........
I just Submitted To another page and now it is coming fine.......  
Here is the code For Another Page
<?php
@session_start();
if($_POST['division'])
{
    $fromDiv =$_POST['division'];
    $divId =explode(',',$fromDiv);
    setcookie("preDiv",$divId[0],time()+60*60*24*365);
    $_SESSION['division'] = $divId[0];
}
header("Location: index.php");
?>


A: Accoroding to this, their is some limit about cookie for a website.
Are you sure you didn't hit the limit?
