Hi all, this is just a quick question with regards to php session data. . .

I have a php built website and I am trying to develop a mobile html / php website to connect to the desktop website.

I can enter my username / password / and secure code, but when ever I try and load the members area it seems the session data is being lost, and the session fails. So I am unable to login through my phone.

I have check, double checked and triple checked the session data variables and they are correct.

Can anyone help, or point me in the right direction

Cheers

Dani AI

Generated

Summary of the situation (from and )
A desktop login flow shows a PHP session and SESS_* values, but the same flow from the iPhone loses state. Printing $_COOKIE/$_SESSION on desktop (as suggested) proved the server-side data exists; the remaining differences are almost always browser/HTTP-level: cookie scope, secure/scheme mismatches, redirects to a different host, or the mobile client not sending the cookie.

Concrete checks and fixes (ordered)

  1. Confirm the mobile browser actually sends the session cookie on every request. Remote-debug with Safari Web Inspector or run the requests through a proxy (Charles/Fiddler) to capture the Set-Cookie and Cookie headers. A quick reproducer via curl (simulate an iPhone UA and save/send cookies) helps rule out client-side blocking:
    curl -i -A "Mozilla/5.0 (iPhone)" -c phone_cookies.txt "https://m.example.com/login"
    curl -i -A "Mozilla/5.0 (iPhone)" -b phone_cookies.txt "https://m.example.com/members/"
  2. Cookie domain/path/secure flags. If the mobile site is on a subdomain (m.example.com) and login sets the cookie on a different host, the cookie will not be sent. Make the session cookie valid for all subdomains before starting the session:
    ini_set('session.cookie_domain', '.example.com');
    session_set_cookie_params(0, '/', '.example.com', /*secure*/ false, /*httponly*/ true);
    session_start();
  3. Scheme and flags. If session.cookie_secure is true but the phone is using HTTP, the cookie will be suppressed. Private/Incognito modes and some webviews also isolate or block cookies.

Server-side/code checks

  • Ensure session_start() runs on every page before accessing $_SESSION and before any output.
  • If redirects send users to a different hostname (or to www vs non-www), the cookie will be lost; keep redirects consistent.
  • If multiple backend servers exist, verify session storage is shared (DB, memcached) or use a sticky session.
  • Check for session_regenerate_id() behavior and call session_write_close() before redirecting.

Quick checklist

  • Capture raw HTTP headers on phone and desktop and compare Set-Cookie/Cookie.
  • Verify cookie domain, path and secure settings.
  • Confirm session_start() placement and no premature output.
  • Inspect server error logs and session_save_path permissions.

These steps narrow the problem to either a client-side cookie not being sent or a domain/scheme mismatch; fixing the cookie scope or the redirect flow usually resolves mobile-only session loss.

Recommended Answers

All 6 Replies

Create a php page to display cookies and session values and then open it with iphone and a desktop. This will help you to understand what is not working. Also check error and access log files in apache.

Hi, many thanks for replying, Its strange as I can login to the website from the desktop m.website.com. . .

but when ever I try to login from my mobile, It's like it doesnt understand the session data. . .

Hi, could you show me how to start with creating cookies and integrating / reading from them into php. . .

I have three session variables ? Do i need to create a cookie for each variable I want to read from ?

How would I read the cookie variable ?

Here's what you can try:

<?php session_start(); ?>
<h3>Cookies</h3>
<pre>
<?php
print_r($_COOKIE);
?>
</pre>
<h3>Session</h3>
<pre>
<?php
print_r($_SESSION);
?>
</pre>

After your login go to this page and check if you get same variables or if something is missing, do this test with the iphone and desktop. I mentioned cookies because I didn't know if you used them or not. I can't help more than this without the code.

Hi, thanks, Iw ill give this a go. I have never used cookies, only session data, im new to php and web design.

When a user enters username and password, it reads from the databse correctly and then sends securecode.php?id=$id (this is also working) as I get the correct id number.

Its just when I enter the securecode, if the code is correct, it will then take the user to the members area, where is reads from the session data and brings back user details from mysql.

The above is working great on the desktop.

Here is the responce from the file u said to upload from the desktop m.

Still unable to login through mobile tho ?

Cookies

    Array
(
    [__utma] => 67449875.1691414763.1322683205.1331604699.1331644165.360
    [__utmz] => 67449875.1331644165.360.38.utmcsr=m.website.co.uk|utmccn=(referral)|utmcmd=referral|utmcct=/directory/
    [__utmc] => 67449875
    [PHPSESSID] => 4dgt5bar5eg1h0np1aeebuhgg3
    [__utmb] => 104626524.3.10.1331649966
)
    

Session

    Array
(
    [SESS_MEMBER_ID] => 81
    [SESS_SECURE_CODE] => a15807d6cc5bd083512906f76b5ca744b25ef5b2
    [SESS_CREFF] => 59632273
)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.