Reputation: 1
I try to pass data from php file to another php file with header function. like that:
header("location:login.php?userName=$username");
(that line appear in the first php file.) the problem is that the data appear in the url of the second php file. like GET. I try looking for some example but without success. i looking for how to make it like POST?
Upvotes: 0
Views: 4782
Reputation: 2042
Originally suggesting to use CURL, I now believe that it might not be the best solution. If you're simply looking to preserve or pass data between scripts, you might want to look into Sessions, which allow you to set and preserve data between scripts.
eg:
Script 1
session_start();
$_SESSION['userName'] = $username;
Script 2
session_start();
if (isset($_SESSION['userName']))
$username = $_SESSION['userName'];
echo $username;
This will successfully pass the value of $username between two scripts. Simply put any variables into the $_SESSION array and they will be available throughout your scripts.
Upvotes: 5
Reputation: 31078
You could use PEAR's excellent HTTP_Request2 package to make POST requests.
Upvotes: 0
Reputation: 318488
You can't. If you redirect you'll always have a GET request.
A possible solution (if the target script is on the same domain) would be using PHP sessions to store the data on the server.
Upvotes: 7