Affichage et suppression de Session
Bonjour,
Dans le cadre d'un projet en PHP, je dois afficher le contenu de ma variable $_SESSION mais ma page me renvoie ma requête comme étant inconnue. Auriez-vous une idée du problème ?
Voici mon code: qui regroupe mes fonctions:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| <?php
/**
* Created by PhpStorm.
* User: StrikerEureka
* Date: 05/04/2016
* Time: 14:28
*/
function creeMenu($menu_param){
//version 3
$string = '<ul>';
foreach($menu_param as $cle => $element){
$string .= "<li id=\"o_$cle\">";
if($element ===''){
$string .= "<h1>$cle</h1>";
} else {
$string .= "<a href='$element' onclick='return false'>$cle</a>";
}
$string .= "</li>";
}
return $string;
//version 2
/*
echo '<ul>';
foreach($menu_param as $cle => $element){
if ($value = ''){
echo "
<li>
<h1>$cle</h1>
</li>
";
} else{
echo " <li>
<a href='$element' onclick='return false'>$cle</a>
</li>
";
}
echo "
<li>
<a href='$element' onclick='return false'>$cle</a>
</li>
";
}
echo '</ul>';*/
};
function chargeAccueil(){
return '<p> Bienvenue voici un peu plus de texte</p>';
}
function chargeTemplate($t){
$file = file('INC/'.$t.'.template.inc.php');
return implode('',$file);
}
function getFormInfo(){
$liste =['_GET'=>$_GET,'_POST' => $_POST, '_FILES' => $_FILES];
echo "<pre>";
return print_r($liste);
echo "</pre>";
}
function chargeConfig(){
return include './useConfig.php';
}
function traiteForm(){
if(!isset($_GET['$array_ini']))
return "Impossible d\'identifier le formulaire";
switch($_POST['$array_ini']){
case 'conifg' : $retour = sauveConfig();
break;
default: $retour = getFormInfo();
}
return $retour;
}
function sauveConfig(){
echo "<pre>";
return getFormInfo();
echo "</pre>";
}
function getSession(){
echo "<pre>";
return print_r($_SESSION);
echo "</pre>";
}
function resetSession(){
return session_destroy();
}
function getContenu($rq){
$contenu ='';
switch($rq){
case 'accueil' : $contenu = chargeAccueil();
break;
case 'profil': $contenu = chargeTemplate($rq);
break;
case 'contact' : $contenu = chargeTemplate($rq);
break;
case 'newAccount' :$contenu = chargeTemplate($rq);
break;
case 'login' : $contenu = chargeTemplate($rq);
break;
case 'config' : $contenu = chargeConfig();
break;
case 'Affiche session' : $contenu = getSession();
break;
case 'Efface session' : $contenu = resetSession();
break;
case 'testForm' : $contenu = traiteForm();
break;
default: $contenu ='Requête inconnue :' .$rq;
}
return $contenu;
} |
Mon JQuery:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| /**
* Created by Killian Kaeses on 05/04/2016.
*/
//Version du point 10
$(document).ready(function () {
// console.log($('.menu'));
$.get("index.php?rq=accueil", function(html) {
$("#contenu").html(html);
});
$('.menu a').click(function(){
var rq = $(this).attr("href").split(".")[0];
var e = $(this);
$.get("index.php?rq=" + rq, function(result){
$("#contenu").html(result);
$('input[type="submit"]').click(function(event){
var rq = $('form').attr('action');
var rq = rq.split(".")[0];
$.get('index.php?rq='+ rq+'&'+$('form').serialize(),function(result){
$('#contenu').html(result);
});
event.preventDefault();
});
});
$('.menu a').removeClass('selected');
$(this).addClass('selected');
$('title').html(rq);
// event.preventDefault();
return false;
});
});
$('#o_Accueil').focus();
//Version avant point 10
/*
$(document).ready(function(){
//console.log($('.menu'));
$('#o_accueil').attr("Class", "selected");
$('.menu a').click(function(){
var e = this;
var rq = e.getAttribute('href');
rq = rq.substring(0, rq.lastIndexOf("."));
$.ajax({
url : "index.php?rq="+rq,
type : 'GET',
success : function(an, statut){
//$(code_html).appendTo("#commentaires");
$("#txtAccueil").html(an);
$('title').html(e.innerHTML);
}
});
var x = document.getElementsByClassName("selected");
var i;
for (i = 0; i < x.length; i++) {
x[i].className = "";
}
this.className = "selected";
});
});
/*function getContenu(e) {
var rq = e.getAttribute('href');
rq = rq.substring(0, rq.lastIndexOf("."));
$.ajax({
url : "index.php?rq="+rq,
type : 'GET',
success : function(an, statut){
//$(code_html).appendTo("#commentaires");
$("#txtAccueil").html(an);
$('title').html(e.innerHTML);
}
});
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtAccueil").innerHTML = xmlhttp.responseText;
var xmlhttp2 = new XMLHttpRequest();
xmlhttp2.onreadystatechange = function() {
if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
document.getElementById("title").innerHTML = xmlhttp2.responseText;
}
};
xmlhttp2.open("GET", "index.php?ti="+xmlhttp.responseText, true);
xmlhttp2.send();
}
};
xmlhttp.open("GET", "index.php?rq="+rq, true);
xmlhttp.send();
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtTab").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "getcourses.php?c="+v, true);
xmlhttp.send();
}*/ |
et mon index:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <?php
/**
* Created by PhpStorm.
* User: Killian Kaeses
* Date: 05/04/2016
* Time: 13:32
*/
/* variables des menus */
$lesMenus = ['menu' =>[ 'accueil' => 'accueil.html',
'contact' => 'contact.html',
'profil' => 'profil.html',
'inscription' => 'newAccount.html',
'connexion' => 'login.html',
'config' => 'config.html'
],
'sous-menu' => ['bienvenue' => '',
'Affiche session' => 'getSession.html',
'Efface session' => 'resetSession.html'
]
];
$cheminIMG = 'IMG/image.png';
$titre = 'Nom de mon site';
$title = 'Acceuil';
$txt = 'Bienvenue';
$nomIMG = 'logo';
include ('INC/mesFonctions.inc.php');
//envoie vers AJAX
if (isset($_GET['rq'])){
$contenu = getContenu($_GET['rq']);
die($contenu);
}
//envoie page index de base
$contenu = getContenu('accueil');
/***** include ******/
include ('INC/layout.html.inc.php');
include ('Config.php');
/****** config ******/
$conf = new Config();
$nomSite = $conf->getData('site','name');
$imageFolder = $conf->getData('image','folder');
$logoName = $conf->getData('logo','name');
$logo = $imageFolder.'/'.$logoName;
$altLogo = $conf->getData('logo','alt');
/****** session *****/
session_start();
$_SESSION['sessionID'] = session_id();
$_SESSION['sessionName'] = 'yolo32';
$_SESSION['ouverture'] = date("H:i:s")." "."le"." ".date("d:F:Y"); |
Merci d'avance