It helps the unset () function, it does not eliminate the variables of $ _SESSION

1

hello I hope you can help me I want to delete specific session variables, but it does not, I'm using the unset function, but my code does not delete the session variables I have two buttons by which depending on which one they choose me to a file php in which are my two options to delete my session variables, sent a variable called option through the url of the page and the value that will be evaluated in my php file that receives these variables but does not and apsera that if it shows me the message that it was executed correctly are not deleted follow the data in the session, this is the code of my php file called cancelCotization.php:

<?php
$opc=htmlentities($_GET['opcion']);

if ($opc='eliminarAll') {
  // code...
  unset($_SESSION['cnombre'],
  $_SESSION['cPriapellido'],
  $_SESSION['cSegapellido'],
  $_SESSION['cdireccion'],
  $_SESSION['cemali'],
  $_SESSION['Ocupacion'],
  $_SESSION['crfc'],
  $_SESSION['telCliTipo'],
  $_SESSION['clitel'],
  $_SESSION["shopping_cart"]);

}else if($opc='eliminarEncargado'){

  unset($_SESSION['cnombre'],
  $_SESSION['cPriapellido'],
  $_SESSION['cSegapellido'],
  $_SESSION['cdireccion'],
  $_SESSION['cemali'],
  $_SESSION['Ocupacion'],
  $_SESSION['crfc'],
  $_SESSION['telCliTipo'],
  $_SESSION['clitel']);
}


header('location:../inicio/index.php');


 ?>

and these are my two buttons which redirect to the same page the two but with different value in the variable option this s the code

<a title="Cancelar esta cotizacion" href="../cotizaciones/cancelarCotizacion.php?opcion=eliminarAll"  class="btn-floating btn-large waves-effect waves-light red" ><i class="material-icons">delete_sweep</i></a>


<a title="eliminar datos de encargado" href="../cotizaciones/cancelarCotizacion.php?opcion=eliminarEncargado" class="btn-floating btn-large waves-effect waves-light green" ><i class="material-icons">voice_over_off</i></a>
    
asked by jose 27.05.2018 в 12:12
source

1 answer

0

Possibly your problem is in if and in elseif

if ($opc='eliminarAll')

This should be if ($opc=='eliminarAll') , you have to have two signs = to compare, as you have it, you are assigned to the variable $opc the value 'elminarAll'

For the else if you also have to put the two signs =

Your code would look like this:

<?php
$opc=htmlentities($_GET['opcion']);

if ($opc=='eliminarAll') {
  // code...
  unset($_SESSION['cnombre'],
  $_SESSION['cPriapellido'],
  $_SESSION['cSegapellido'],
  $_SESSION['cdireccion'],
  $_SESSION['cemali'],
  $_SESSION['Ocupacion'],
  $_SESSION['crfc'],
  $_SESSION['telCliTipo'],
  $_SESSION['clitel'],
  $_SESSION["shopping_cart"]);

}else if($opc=='eliminarEncargado'){

  unset($_SESSION['cnombre'],
  $_SESSION['cPriapellido'],
  $_SESSION['cSegapellido'],
  $_SESSION['cdireccion'],
  $_SESSION['cemali'],
  $_SESSION['Ocupacion'],
  $_SESSION['crfc'],
  $_SESSION['telCliTipo'],
  $_SESSION['clitel']);
}


header('location:../inicio/index.php');


 ?>
    
answered by 27.05.2018 / 12:27
source