| | |
Problems with session_unregister and / or unset()
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hey all! Sorry I haven't been around much lately. Hope things are well cscgal! :cheesy:
I'm working on a new function for the admin control panel of my site.
When a user logs in, it checks to see if it's a normal user, and then if not, checks to see if it is the administrator (me).
I've set up a select menu that allows me to log in as the "normal user" after I've logged in as admin. That part works fine, and I am logged in with admin permissions, yet, am viewing the control panel as the normal user would.
I have created a "switch" script that should unset the session vars that are registered for the normal user, which are company_id and cname, which hold obvious values.
However, when I use the script to unset the variables to either return to admin only, or switch to a new company, for some reason the session vars aren't being cleared, but it only happens on the page in which I registered the variables to begin with. The variables are registered in the header include, so this can occur on almost any page of the admin section...
Here is the contents of my "switch" script, which should unset the variables, and return me to the main page of the control panel...
Most of my session functions are fairly simple, so I'm totally confused on what may be wrong...
[PHP]
<?
session_start();
global $valid_user; // username
global $company_id, $cname;
// I added this section to make sure it wasn't caching the page
header("Cache-Control: no-cache");
header("Cache-Control: post-check=0,pre-check=0");
header("Cache-Control: max-age=0");
header("Pragma: no-cache");
// End
session_unregister("company_id");
session_unregister("cname");
unset($cname, $company_id, $_SESSION['company_id'], $_SESSION['cname']);
header ("Location: $acp_location");
?>
[/PHP]
Any Ideas???
Thanks in Advance!!!
I'm working on a new function for the admin control panel of my site.
When a user logs in, it checks to see if it's a normal user, and then if not, checks to see if it is the administrator (me).
I've set up a select menu that allows me to log in as the "normal user" after I've logged in as admin. That part works fine, and I am logged in with admin permissions, yet, am viewing the control panel as the normal user would.
I have created a "switch" script that should unset the session vars that are registered for the normal user, which are company_id and cname, which hold obvious values.
However, when I use the script to unset the variables to either return to admin only, or switch to a new company, for some reason the session vars aren't being cleared, but it only happens on the page in which I registered the variables to begin with. The variables are registered in the header include, so this can occur on almost any page of the admin section...
Here is the contents of my "switch" script, which should unset the variables, and return me to the main page of the control panel...
Most of my session functions are fairly simple, so I'm totally confused on what may be wrong...
[PHP]
<?
session_start();
global $valid_user; // username
global $company_id, $cname;
// I added this section to make sure it wasn't caching the page
header("Cache-Control: no-cache");
header("Cache-Control: post-check=0,pre-check=0");
header("Cache-Control: max-age=0");
header("Pragma: no-cache");
// End
session_unregister("company_id");
session_unregister("cname");
unset($cname, $company_id, $_SESSION['company_id'], $_SESSION['cname']);
header ("Location: $acp_location");
?>
[/PHP]
Any Ideas???
Thanks in Advance!!!
Just a quick question: are you trying this on a Windows server or Linux? I had a similar problem where I could not unset the session variables. I tried everything and posted on every forum I could think of. Nothing worked. I moved the app to a Linux server and it worked. Strange. Maybe a fault with the version of PHP I was using.
Check out my blog at http://www.shinylight.com for more stuff about web dev.
![]() |
Similar Threads
- If i use an illegal copy of windows,will it cause problems? (Windows NT / 2000 / XP)
- problems with sessions and login.php (PHP)
- Connection Problems (Networking Hardware Configuration)
- Pop up ads (Web Browsers)
- No time... bitch load of problems (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: php error when using invision board
- Next Thread: Next and previous links
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






