lokendra.khandelwal Posted May 26, 2008 Share Posted May 26, 2008 I can not able to set cookie on mobile emulator by using php standard function setcookie('testCookie','12345') nor i able to retrieve by using $_COOKIE[cookieName].Can anybody help me on this. Thanks in advance, Lokendra Quote Link to comment Share on other sites More sharing options...
deadonarrival Posted May 26, 2008 Share Posted May 26, 2008 You're setting the cookie testCookie,but retrieving cookieName? Or is that just where you're trying to expain your problem? If not it sounds like it may be a problem with the emulator, why not try an actual mobile device? Quote Link to comment Share on other sites More sharing options...
lokendra.khandelwal Posted May 26, 2008 Author Share Posted May 26, 2008 I am just taking an example cookieName means 'testCookie' in this example. When i tried opeing wap.goggle.com in mobile emulator its two set cookies. Waiting for your response, Thanks buddy... Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 26, 2008 Share Posted May 26, 2008 can we see your code change the names of the cookies and personal info we do not need Quote Link to comment Share on other sites More sharing options...
lokendra.khandelwal Posted May 26, 2008 Author Share Posted May 26, 2008 <?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..... Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 26, 2008 Share Posted May 26, 2008 thats the problem mate there is no possible way i know for it to work like that <?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> Quote Link to comment Share on other sites More sharing options...
lokendra.khandelwal Posted May 26, 2008 Author Share Posted May 26, 2008 Hey try to find out solution on google ..... please..... thanks Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 26, 2008 Share Posted May 26, 2008 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; } ?> Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 26, 2008 Share Posted May 26, 2008 Wen working with JavaME, I use the Sun Java Wireless Toolkit (for CLDC). You can set the phone type, capabilities, memory database, security, bluetooth, etc, maybe this will help? Quote Link to comment Share on other sites More sharing options...
lokendra.khandelwal Posted May 26, 2008 Author Share Posted May 26, 2008 No buddy its not working.... Not on simple browsers. Header Already Sent Error Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 26, 2008 Share Posted May 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
lokendra.khandelwal Posted May 28, 2008 Author Share Posted May 28, 2008 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); Quote Link to comment Share on other sites More sharing options...
deadonarrival Posted May 28, 2008 Share Posted May 28, 2008 I thought it must be, the code was faultless. I'm glad it's sorted, and sorry I didn't have enough experience with that emulator to be more help. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 28, 2008 Share Posted May 28, 2008 By the way, you can't access a cookie's value on the same page it's set. =P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.