ho creato un file index.php
codice:
<
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento senza titolo</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script><script>
function cancella() {
var xhr = new XMLHttpRequest;
xhr.open("get", "cancella_variabile.php", true);
xhr.send();
}
function inserisci() {
var xhr = new XMLHttpRequest;
xhr.open("get", "inserisci_variabile.php?a=1", true);
xhr.send();
}
</script>
</head>
<?php
$a = $_SESSION["cliente"];
echo "<script>alert('".$a."');</script>";
?>
<body>
<a href="" onClick="inserisci()">inserisci</a>
<a href="" onClick="cancella()">cancella</a>
</body>
</html>
poi il file inserisci_variabile.php così:
codice:
<?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento senza titolo</title>
</head>
<body>
<?php
echo "<script>alert('ciao');</script>";
$_SESSION["cliente"] = $_GET['cliente'];
?>
</body>
</html>
e il file cancella_variabile.php così:
codice:
<?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento senza titolo</title>
</head>
<body>
<?php
unset($_SESSION["cliente"]);
?>
</body>
</html>
Cosa sbaglio?