PHP5: can cookies be set in mobile devices? (Iphones)

Posted on 2014-08-07
Last Modified: 2014-08-08
Hello Experts,

I may be asking multiple questions in one...

I am starting my php sessions as follows:

ini_set('session.use_only_cookies', 1);
$lifetime = 300;

session_set_cookie_params( $lifetime, '/', 'localhost', false, true );

$cookieName = "test";
$value = 4;
setcookie( $cookieName, $value, time() + $lifetime, '/', 'localhost', false, true );

Open in new window

but, I am unable to set it when testing using my mobile devices...

so, is there another way to initialize sessions in mobile devices?

Question by:epifanio67
    LVL 58

    Assisted Solution

    What version are you using?
    Check the cookie settings under Privacy & Security
    LVL 82

    Assisted Solution

    by:Dave Baldwin
    In the sites that I maintain, there is no difference between sessions on mobile and desktop devices.  All the mobile browsers that I'm aware of support cookies.  Try the very simple example on the session_start page:
    LVL 107

    Accepted Solution


    Author Closing Comment

    Thank you experts for your help...

    I found the issue... see code below....

    ini_set('session.use_only_cookies', 1);
    $lifetime = 300;//expire in 5 min
    session_set_cookie_params( time() + $lifetime, '/', 'localhost', false, true );

    $cookieName = 'test.session3.cookiename';
    $testValue = 'testest';
    //this works...set cookie ok in firefox, Opera, Chrome, IE10
    // setcookie( $cookieName, $testValue, time() + $lifetime );

    //this doesn't work.. sets cookie ok ONLY in firefox
    setcookie( $cookieName, $testValue, time() + $lifetime, '/', 'localhost', false, true );

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now