TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-30-2008, 01:10 AM   #1 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default kill only one session key and keep others

Hi !

I currently use two sessions in my PHP5 API.
$_SESSION["user"] which contains the serialized instance of my "User" class. Allowing me to know who is the current visitor.
$_SESSION["tpl"] which contains the selected design.

I would like to destroy $_SESSION["user"] but keep $_SESSION["tpl"].
session_unset destroy all session data, session_destroy too, unset($_SESSION["user"]) doesn't work.

Here is my code:

PHP Code:
if(!empty($_POST['deco']) && $this->login != "none")
{
    unset(
$_SESSION["user"]);
    
header("location:".((!empty($_GET['page'])) ? $_GET['page'].((!empty($_GET['id'])) ? "-".$_GET['id'] : "") : "").".html");
}
// the header is strange but works, I've well tested it. 
Thank you for your ideas.
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 03-30-2008, 01:24 AM   #2 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

unset($_SESSION['user']) should work... strange

try

$_SESSION['user'] = '';

and then check it with empty()
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 03-30-2008, 02:52 AM   #3 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Also check this topic out, about headers ;) The Dangers of the Header Function
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
The Following User Says Thank You to Nor For This Useful Post:
Gibou (03-30-2008)
Old 03-30-2008, 04:46 AM   #4 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

PHP Code:
<?php

$_SESSION
['user'] = "Orc";
$_SESSION['a'] = "this is a test"# merely a test
function DeleteElement($input$key)
{

    if (
array_key_exists($key,$input))
    {

            unset(
$_SESSION[$key]);
            
$tplArray = array('tpl');
            
$new array_fill_keys($tplArray,'my_templates');
            
$_SESSION['tpl'] = $new['tpl'];
            
print_r($_SESSION); # You can take this out if you want
        
    
}
}


DeleteElement($_SESSION'user');

echo 
$_SESSION['tpl']; # Which gives you My_templates


?>
Okay, I came up with this function that deletes an element by key in the Array, this can definitely be improved cause its only adding a new key and val by what you said 'tpl' soo..

Try this, I don't even know if I did exactly what you requested.

Which gave me this:
PHP Code:

Array
(
    [
a] => this is test
    
[tpl] => my_templates
)
my_templates 
Now I understand $_SESSION is an associative array, so fiddle with it.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 03-30-2008, 09:55 AM   #5 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

Thank you Nor, it was exactly my problem ! :)
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 03-30-2008, 08:32 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Well my time was wasted.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:15 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design