0
I wanted to know if there is any way for me to save two values in the same variable Session as if it were an array, because I want to save both the value of input text and the wysiwyg element by clicking the "save chapter" button on the image, I tried to save it like this:
<?php
session_start();
$titulo = isset($_POST['titulo']) ? $_POST['titulo'] : '';
$paragrafo = isset($_POST['valor_paragrafo']) ? $_POST['valor_paragrafo'] : '';
$p = $_GET['p'];
$_SESSION[$p][0] = $titulo; //aqui salvaria os valores na session
$_SESSION[$p][1] = $paragrafo;
?>
Only when I go to display on the screen, if I save this way, on the screen at the time I will display, appears only the letter related to the Dice that I put in Sesssion instead of all the text. code to display the values on the screen:
$(document).ready(function() {
$("#paragrafo").Editor();
$('#paragrafo').Editor('setText', '<?=addslashes($_SESSION["$p"][1])?>');
$('#titulo').val('<?=($_SESSION["$p"][0])?>');
});
the first php code posts come from this html and javascript:
function Envia_Form(valor, arquivo, chooser, target){ //valor do chooser: 0 = faz submit com refresh na pagina | 1 = sem refresh na pagina
$("#valor_paragrafo").val(valor);
if(chooser == 0){
$("#form").attr("action",arquivo);
if(target != ''){
$("#form").prop("target", target);
}
document.form.submit();
} else if(chooser == 1){
$.post(
arquivo,
$('#form').serialize(),
function( data ){
}
);
}
}
<form id="form" name="form" method="post" action="proc.php">
<div class="titulo">TÍTULO
<input type="text" class="titulo-input" name="titulo" id="titulo" placeholder="Digite o texto">
</div>
<div class="container-fluid">
<div class="row">
<div id="paragrafo" name="paragrafo"></div>
<input type="hidden" id="valor_paragrafo" name="valor_paragrafo" />
</div>
<p>
<br>
<input type="button" value="Salvar Capítulo" onclick="Envia_Form($('#paragrafo').Editor('getText'), 'salva_paragrafo.php?p=<?=$p?>', 1);" />
<input type="button" value="Gerar PDF" onclick="Envia_Form($('#paragrafo').Editor('getText'), 'proc.php', 0, '_blank');" />
</p>
but what would I need to do about the get? this 10-1 input I had switched on purpose to see if it changed the value that appeared in the html fields, and really changed, only I keep appearing a single letter :/
– alexandre9865
session_destroy
is obsolete, prefers to do something like:$_SESSION['aula'] = NULL;
– Guilherme Nascimento
@Guilhermenascimento why session_destroy is obsolete? wouldn’t session_unset be obsolete??
– alexandre9865
@Alexandremartinsmontebelo pardon confused me, the problem is that
session_destroy
, his problem is that it will destroy variables beyond$_SESSION['aula']
, what can affect other system functionalities, the best way is the$_SESSION['aula'] = NULL;
, prefer to use thesession_destroy
if you’re really sure what you’re doing.– Guilherme Nascimento
ah yes, in the system I’m only using session_destroy when the user clicks "exit", yes, there is a login system also in that system
– alexandre9865
@Alexandremartinsmontebelo but that’s what I’m saying, session_destroy will delete everything from that session, if you have other data from other applications that do not need to be logged in to work they will also be removed, summarizing can use, but only when really necessary. The recommended is to use
$_SESSION['aula'] = NULL;
and then check withif (empty($_SESSION['aula']) === false) { ... }
if it is logged in.– Guilherme Nascimento
And then it worked?
– Ríder Cantuária