Last active
August 29, 2015 14:02
-
-
Save dgmike/a375ada5aab97cbdcdb7 to your computer and use it in GitHub Desktop.
PHP: simple use of session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php session_start(); ?> | |
<form action="/manda-email.php"> | |
<textarea name="texto">Gostaria de fazer um orçamento para os seguintes produtos: | |
<?php | |
if (isset($_SESSION['produtos'])) { | |
echo implode("\n", $_SESSION['produtos']); | |
} | |
?></textarea></form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if (isset($_GET['produto']) && (int) $_GET['produto']) { | |
if (!isset($_SESSION['produtos'])) { | |
$_SESSION['produtos'] = array(); | |
} | |
$_SESSION['produtos'][] = funcao_que_vai_processar_o_id_do_produto_e_convertelo_em_algo_descritivo($_GET['produto']); | |
header('Location: /contato.php'); // este eh o redirect | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment