Opera Mini and PHP sessions
I tried to transfer sensitive information from 1 page to the next using Cookies and PHP Sessions but still no luck. This works great in all browsers I've tested except Opera Mini. I also found this: http://caniuse.com/#search=cookie
This is how I set it up now.
page1.php:
<?php
session_start();
$time = time();
$key = '';
$hash = md5($key . $time);
$_SESSION['inno'] = '';
header("Location: page2.php". $hash);
exit;
?>
page2.php:
<?php
session_start();
if (isset( $_SESSION['inno'])) {
include("../global/header.php");
include("../global/content.php");
}
session_destroy();
?>
The content of the page is confidential, so it went from page1.php to page2.php.
Is there some workaround for this if the transfer of information in this mode is not supported in Opera Mini?
+3
source to share
1 answer
Use classes for reusable resources, they are less messy.
It looks like you forgot to assign data, so
Here's a promising structure:
index.php
<?php
include_once 'session.php';
$my_session = new session_helper;
//SET YOUR SESSION VARIABLES
if($my_session->get_session_data('username') == null){
$sessionData = array(
'username'=>'me',
'logged'=>true,
'password'=>md5('password')
);
$my_session->set_session_data($sessionData);
}
?>
<a href="view_session.php">View my session</a>
view_session.php
<?php
include_once 'session.php';
$my_session = new session_helper;
?>
<!--GET YOUR SESSION VARIABLES-->
<p>Username: <?php echo $my_session->get_session_data('username'); ?></p>
<p>Logged: <?php echo $my_session->get_session_data('logged'); ?></p>
<p>Password: <?php echo $my_session->get_session_data('password'); ?></p>
<p> </p>
<?php $my_session->debug_session(); ?>
session.php to get rid of headaches
<?php
//MANAGE YOUR SESSION
class session_helper
{
//Start session when class instance created
function __construct()
{
session_start();
}
//Session data set using an array to easily add multiple values e.g. on login page
function set_session_data($sessionData)
{
forEach($sessionData as $key => $value){//Go through each key
$_SESSION[$key] = $value;//And assign it to session
}
}
function get_session_data($session_data_key)
{
return $_SESSION[$session_data_key];//Call this to get your values
}
function debug_session()
{
print_r($_SESSION); //Check what session contains if something is wrong
}
function close_session()
{
session_destroy(); //Good to use for fresh start/logout.
}
}
?>
- session.php manages sessions. Accessing will directly result in a blank page exiting.
- index.php uses a condition to set variables. You don't have to recycle the data every time you have it.
- view_session.php has all the session information.
- The best practice for getting information is to store the secure / encrypted primary keys of the database and then use them to fetch everything else from the database, for example. by user ID, get email address, profile creation time, first name, last name, etc.
0
source to share