Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variables received in GET string through a php header redirect?

I'm receiving values in a GET string from Aweber upon user's submission of a form. I take the variables they send and submit them to a SMS gateway to notify a 3rd party of the submission by text message.

Here's my problem. I need to redirect the page that performs the outgoing SMS commands in a php header to another page that finally displays the GET variables sent from Aweber.

I can retrieve the variables and their values in the first page. How do I pass them to the second page?

Here is the code I'm using on the first page (sms.php) to collect the variables sent by Aweber:

   $fname   = $_GET['name'];
   $femail  = $_GET['email'];
   $fphone  = $_GET['telephone'];
   ....etc

   header('Location: confirmed.php');
   exit;
like image 795
user1322707 Avatar asked Aug 03 '12 21:08

user1322707


People also ask

How to pass variable with redirect in PHP?

Use the header() Function in PHP to Send URL as HTTP Header to the Browser. We can use the header() function, which takes Location as a parameter. The value of Location is the URL of the desired page, which we need to redirect. Note that the header function should be written above the HTML tags and texts in the file.

How to pass parameters in header Location in PHP?

Change the single quotes to double quotes: header("Location: http://localhost/blast/v2/?$qry"); A single quoted string in PHP is treated as a string literal, which is not parsed for variables. Double quoted strings are parsed for variables, so you will get whatever $qry contains appended, instead of literally $qry .

How to redirect to GET method in PHP?

In PHP, when you want to redirect a user from one page to another page, you need to use the header() function. The header function allows you to send a raw HTTP location header, which performs the actual redirection as we discussed in the previous section.

What does header () do in PHP?

The header() function in PHP sends a raw HTTP header to a client or browser. Before HTML, XML, JSON, or other output is given to a browser or client, the server sends raw data as header information with the request (particularly HTTP Request).


2 Answers

Please for anyone reading this in future, use sessions for this kind of variable value transfer because if you rely mostly on adding variable to header then if the user in still on that form and carries out an action that changes the value of the header then your own variable value changes since it depends on the header......simply put, USE SESSIONS.

like image 94
david.ee Avatar answered Oct 21 '22 17:10

david.ee


session_start();
$_SESSION['fname']   = $_GET['name'];
$_SESSION['femail']  = $_GET['email'];
$_SESSION['fphone']  = $_GET['telephone'];
....etc

header('Location: confirmed.php');

and get it on the next page like:

session_start();
$fname   = $_SESSION['fname'];
$femail  = $_SESSION['femail'];
$fphone  = $_SESSION['fphone'];

....etc

like image 20
Kalpesh Avatar answered Oct 21 '22 18:10

Kalpesh