I am calling another php file from my current php and I would like send a variable through. I am doing it this way but it fails. What am I doing wrong?
<?php
session_start();
ob_start();
require dirname(__FILE__).'/GenerateFile.php?zip=true';
header("Refresh: 0");
?>
>Solution :
To send a variable to another PHP file, you can pass it as a parameter in the URL
or you can use the session variables.
However, the method you’re currently using is incorrect.
<?php session_start();
ob_start();
$_GET['zip'] = 'true'; // Set the value of 'zip' parameter
require dirname(__FILE__).'/GenerateFile.php'; // Include the PHP file
header("Refresh: 0");
header("Location: ".$_SERVER['PHP_SELF']);
// Redirect or refresh the current page
exit(); ?>
You can set the value of the zip parameter in $_GET array to ‘true’.
Then, include the GenerateFile.php file without using the URL.
After that, refresh or redirect the current page using header("Location: ".$_SERVER[‘PHP_SELF’]).
Then Finally, you will use exit() to terminate the current script.
Remember the file path in the require statement is correct
& that GenerateFile.php file expects the zip parameter to be present in the $_GET array.