nth nth - 4 months ago 10
PHP Question

can i show what i entered input into sessions?

i want display all with session what i enter into input.. but only one shows .. i want display past results too with session.. here my codes;

<form method="post">

isim gir
<input type="text" name="isim" id="isim[]" />
<input type="submit" name="gir" value="sözler" />

</form>

<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}

if(isset($_POST["gir"])){
$isim=$_POST["isim"];
echo $_SESSION["name"]=$isim;
}
?>

Answer

Create a search_history session variable that contains an array of all the searches.

if (!isset($_SESSION['search_history'])) {
    $_SESSION['search_history'] = array();
}

if (isset($_POST['gir'])) {
    $isim = $_POST['isim'];
    $_SESSION['search_history'][] = $isim;
}