473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,394 developers and data experts.

how to work with sessions when cookies are disabled

1,059 1GB
In general sense:
If Cookie is disabled by browser session do not work.
The most common case is mobile phone browser. In mobile phone browser cookie is disabled by default.

But Session and Cookie is strongly co-related. Because using cookie value server can recall which user is currently requesting.

Solution:
To make the solution understandable I have made three php file.
play.php
play2.php
play3.php


creating session
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //play.php
  3. session_start();
  4. ?>
  5. <form action="play2.php" method="post">
  6. <input type=text name="name">
  7. <input type=hidden value=<?php echo (session_name());?> name="session_name">
  8. <input type=hidden value=<?php echo (session_id());?> name="session_id">
  9. <input type=submit>
  10. </form>
  11.  
in play.php session has been create
After creating the session name and id is stored in hidden field.
storing two hidden field is not necessary. necessary part is session_id(). There is also a text field which will be stored through the play2.php in session

//save a text in the session which was created in play.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //play2.php
  3. $_COOKIE[$_POST['session_name']]=$_POST['session_id'];
  4. session_start();
  5. $_SESSION['myname']=$_POST['name'];
  6. ?>
  7. Some informatoin
  8. <br>
  9. <br>
  10. <a href="play3.php?session_name=<?php echo (session_name());?>&session_id=<?php echo (session_id());?>">go to next page</>
  11.  
  12.  
Here is the magic started
Interestingly session_start() function take the session id from $_SESSION['PHPSESSID']. What we did is create a cookie name PHPSESSID and store the session value from POST data. After that we called session_stat() function. and next thing the value from the text field to session.

//restoring value from session which is saved in play2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //play3.php
  3. $_COOKIE[$_GET['session_name']]=$_GET['session_id'];
  4. session_start();
  5. echo $_SESSION['myname'];
  6. ?>
  7.  
Play3.php simply shows the session value and session is create from GET data
Jul 26 '10 #1
3 11672
Dormilich
8,658 Expert Mod 8TB
I may note that the default fallback for disabled cookies is putting the Session ID in the URL (unless this is explicitly forbidden)
Jul 26 '10 #2
johny10151981
1,059 1GB
This solution is only solution for me so far. But I would like if we can have a better solution :)
Jul 26 '10 #3
TheServant
1,168 Expert 1GB
I cannot think of anything. You maybe able to go a javascript/AJAX way, but it means special handling of every link over your whole site and that is probably a bit too much effort for what it's worth.

Actually, another way would be to bypass sessions... I have never tried this, but if on every page you store in a database: IP address, Browser, and time, and then every page check if that is matched, you could potentially retrieve the "most likely" data for that person. This will be more vunerable to hijacks, and will put strain on the DB/server depending on traffic, but will essentially be a manual session.
Jul 28 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Anonymous | last post by:
Hi! I've got an unusual problem here. I'm trying to write a PHP script that behaves like a web client. Why? I want to automatically check specific URLs for changes. I'm using...
2
by: What-a-Tool | last post by:
I am using a couple of session variables in my site. From what I can figure out, session information is stored on the users computer in a cookie - If the user has cookies disabled, do session...
1
by: Andreas Klemt | last post by:
Hello, how can I kill all running sessions when working with ASP.NET Session State Service? Is there any VB.NET code for that? Thanks for any help in advance! Andreas
7
by: Atte André Jensen | last post by:
Hi I'm developing a site where I'd like to store information during a users visit. So far I've been using sessions, but as far as I can tell it's not possible to control for how long a session...
5
by: frothpoker | last post by:
Guys, I have a couple of issues which I am hoping you can provide guidance on... First one:- Is there any way to retain the $_POST values when a user navigates between pages without using...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
3
by: Griff | last post by:
UserA has a PC running IE 6. This has the cookies disabled: 1 - Override automatic cookie handling: checked 2 - First party cookies: Block 3 - Third-party cookies: Block 4 - Always allow session...
5
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet...
13
pradeepjain
by: pradeepjain | last post by:
hii guys , I am giving a presentation on sessions and cookies. i want to say points which are really worth telling . So i need some points about sessions and cookies which needs to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.