Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get data in php from URL

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading