Jump to content

Recommended Posts

Im having issues destroying a session and then re-creating the session again.  Its easier to show the code.

 

First of all I have a form that shows you different business details.

<form action="" method="POST" id="mybusfrm">
       <ul id="bus_list"> 
     	 <li><input  type="image" src="<?php  if ($CP['logo']=='logo_default.jpg') 
					{ echo "/images/logo_default.jpg"; }
   else { echo	"/members/images/{$CP['county']}/{$CP['logo']}"; }
   ?>" width="60" height="60" id="businsert" name="businsert" />
      	</li>
      	<li><?php echo $CP['name']; ?></li>
       <input name="bus" type="hidden" value="<?php echo $CP['busID'];?>">
       <input name="pap" type="hidden" value="<?php echo $CP['permission'];?>">
       </ul>
     </form>

 

I have two hidden fields with the business ID and the users permission.  The information that displays on the page is taken from the session

 

$_SESSION['busID']

 

This session is fed through a function that gets the details.

 

Before that obviously if the user clicks a different business then the page needs to update with the business details from the newly replaced session variable. so for the  code that changes the variable name.

 

if(isset($_POST['businsert_x'])){	
session_destroy($_SESSION['busID']);
session_destroy($_SESSION['pap']);	
$bus = trim($_POST['bus']);
$pap = trim($_POST['pap']);	
if (is_numeric($bus) && is_numeric($pap)) {
$bus = mysql_real_escape_string($bus);
$pap = mysql_real_escape_string($pap);
$_SESSION['busID'] = $bus;
$_SESSION['pap'] = $pap;
$url = "index.php";        
header("Location: $url");
}
else {echo "Fail";}}
//end check club

 

This code has been previously working but for some reason its now stopped.  Also I get a logo error of

 

 

Wrong parameter count for session_destroy() in /home/sites/site.com/public_html/members/index.php on line 10, referer: http://www.site.com/members/index.php

 

there is also one for line 11.  These two lines are the session_destroy($_SESSION['busID']); lines respectively.

 

I have tried adding to the page refresh......

 

$url = "index.php/business='$busID'&'$pap'";

 

To see if the variables are even changing when a different business is selected and they do. 

 

Please help.

 

Thanx

Link to comment
https://forums.phpfreaks.com/topic/240553-session_destroy/
Share on other sites

session_destroy destroys the entire session, not an individual variable stored in the session. To remove a variable from a session you can just unset it:

 

if(isset($_POST['businsert_x'])){
unset($_SESSION['busID'], $_SESSION['pap']);

 

This code has been previously working but for some reason its now stopped.

Most likely this code has always been throwing an error. Your error_reporting value was probably set in such a way as to prevent the errors from being displayed.

Link to comment
https://forums.phpfreaks.com/topic/240553-session_destroy/#findComment-1235616
Share on other sites

Ok thats great thank you. I have changed that but the page is still not updating with the new business details. After that form has processed i am left with a new

 

$_SESSION variable (which is basically an ID)

 

then I have this code


$Thebus = TheBus($_SESSION['busID']);


echo $Thebus['name'];

 

and the function

 


function TheBus($busID)	 {
	$Thebusq = mysql_query("SELECT * FROM business WHERE busID = '$busID'");
$Thebus = mysql_fetch_array($Thebusq);
return $Thebus;

}

Link to comment
https://forums.phpfreaks.com/topic/240553-session_destroy/#findComment-1235629
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.