Let's say: in file Cat.php, I made a variable called $Kitty. On the other hand, I have another file called Dog.php. Now I wanna echo the variable $Kitty in the file Dog.php, how do I do that?
This is my code in the Dog.php file:
<!DOCTYPE html>
<html>
<body>
<?php include 'cat.php';
echo $kitty;
?>
</body>
</html>
Use include
, like this:
<?php include('Cat.php'); echo $Kitty ?>
You can use the session variable. in cat.php
<?php
session_start();
$_SESSION['cat']=$Kitty;
?>
Now in dog.php
<?php
session_start();
echo $_SESSION['cat'];
session_destroy();
?>