how to use php IF looping to show value of a variable that taken from method GET on previous link?

49 views Asked by At
<?php
include "global_database_function.php"; //include config file
$nama_kategori = $_GET['nama_kategori']; //get from previous link
//global $nama_kategori; 
//i can't use global $name_kategori

$idkategori = $_GET['idkategori'];
?>
<html>
<head>
</head>
<body>
<?php
//continue only if $_POST is set and it is a Ajax request
if(isset($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{   
  //here is the code i try to show, i try to use:
   htmlspecialchars($nama_kategori);
}
?>
</body>
</html>

if I put htmlspecialchars($nama_kategori); between body and if(isset($_POST) && isset, the value of $nama_kategori is visible.

1

There are 1 answers

0
Rohit Kumar On

Let it store into session for future as

$nama_kategori = $_GET['nama_kategori'];
session_start();
$_SESSION['t']=$nama_kategori;

and when needed

if(isset($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{ 
session_start();  
echo $_SESSION['t'];
}