Jump to content

set cookie not working on mobile


Recommended Posts

<?php

setcookie('testCookie', '123456');

header("Set-Cookie: testCookie1=present");

?>

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<META HTTP-EQUIV="Set-Cookie"

CONTENT="feedme=1;path=/">

</head>

<body>

        <?php echo $_COOKIE['testCookie'];?>

        <br />

<?php echo $_COOKIE['testCookie1'];?>

<br />

<?php echo $_COOKIE['feedme'];?>

</body>

</html>

 

 

I am trying either by using setcookie or header or by meta tag

 

nothing works..... :(

thats the problem mate there is no possible way i know for it to work like that :P

 

 

<?php    
   setcookie('testCookie', '123456');
?>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
        <?php echo $_COOKIE['testCookie'];?>
      
</body>
</html>

i found this on the PHP manual i hope it helps ;)

 

<?php

    function createCookie($name, $value='', $maxage=0, $path='', $domain='', $secure=false, $HTTPOnly=false)
    {
        $ob = ini_get('output_buffering');

        // Abort the method if headers have already been sent, except when output buffering has been enabled
        if ( headers_sent() && (bool) $ob === false || strtolower($ob) == 'off' )
            return false;

        if ( !empty($domain) )
        {
            // Fix the domain to accept domains with and without 'www.'.
            if ( strtolower( substr($domain, 0, 4) ) == 'www.' ) $domain = substr($domain, 4);
            // Add the dot prefix to ensure compatibility with subdomains
            if ( substr($domain, 0, 1) != '.' ) $domain = '.'.$domain;

            // Remove port information.
            $port = strpos($domain, ':');

            if ( $port !== false ) $domain = substr($domain, 0, $port);
        }

        // Prevent "headers already sent" error with utf8 support (BOM)
        //if ( utf8_support ) header('Content-Type: text/html; charset=utf-8');

        header('Set-Cookie: '.rawurlencode($name).'='.rawurlencode($value)
                                    .(empty($domain) ? '' : '; Domain='.$domain)
                                    .(empty($maxage) ? '' : '; Max-Age='.$maxage)
                                    .(empty($path) ? '' : '; Path='.$path)
                                    .(!$secure ? '' : '; Secure')
                                    .(!$HTTPOnly ? '' : '; HttpOnly'), false);
        return true;
    } ?>

if you are getting a header sent error might try ob_start() wont get rid of the problem entirely, for that you will need to make sure all code comes after the header and not before. header() should be the first code on the page usually. before all output to HTML/CSS. ;)

Hi All,

 

specially darkfreaks and deadonarrival....

 

 

I found the solution for this. As with "Openwave_v70_Simulator" it will not set cookies when we work on localhost.

 

And above these three methods for setting up the cookie only one will work i.e. with header

 

header("Set-Cookie: sessChk=".$better_token, time() + 3600);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.