Reputation: 5
Hey i have the following issues / thinking problem
<?php
$fname=$_GET['buyer_first_name'];
$lname=$_GET['buyer_last_name'];
$email=$_GET['buyer_email'];
$orderid=$_GET['order_id']
?>
This parameters will coming in by GET and after they get in / i would love an automatic redirect to the following URL with the above parameters in it
www.mydomain.com/query.php?k=test&action=add&r=$orderid&n=$email
How can i do that? My main problem is how i can set the different parameters in the url..
Upvotes: 0
Views: 102
Reputation: 163187
You can first check the $_SERVER['REQUEST_METHOD']
if it is a 'GET' and check if all your expected parameters are set.
Then you can use http_build_query to build your url and use header to go to your url.
if (
$_SERVER['REQUEST_METHOD'] === 'GET' &&
isset($_GET['buyer_first_name']) &&
isset($_GET['buyer_last_name']) &&
isset($_GET['buyer_email']) &&
$_GET['order_id']
) {
$params = array(
'k' => 'test',
'action' => 'add',
'r' => $_GET['order_id'],
'n' => $_GET['buyer_email']
);
$url = 'www.mydomain.com/query.php?' . http_build_query($params);
header("location:" . $url);
}
Upvotes: 1
Reputation: 760
$querystring = "www.websitedomain.com/redirect.php?".$_SERVER['QUERY_STRING'];
header('location:'.$querystring);
Upvotes: 0
Reputation: 3488
You can use as below :
<?php
$fname='';$lname='';$email='';$orderid='';
if(isset($_GET['buyer_first_name']))
$fname=stripslashes($_GET['buyer_first_name']);
if(isset($_GET['buyer_last_name']))
$lname=stripslashes($_GET['buyer_last_name']);
if(isset($_GET['buyer_email']))
$email=stripslashes($_GET['buyer_email']);
if(isset($_GET['order_id']))
$orderid=stripslashes($_GET['order_id']);
$fullurl = "www.mydomain.com/query.php?k=test&action=add&r=".$orderid."&n=".$email;
header("location:".$fullurl);
?>
Upvotes: 0
Reputation: 1175
http_build_query is a cool function
$parameters = array(
'k' => 'test',
'action' => 'add',
'r' => $orderid,
'n' => $email,
);
$target = 'www.mydomain.com/query.php';
$url = $target.'?'.http_build_query($parameters);
header("location: $url");
Upvotes: 0
Reputation: 33804
This should pretty much do what you are trying to accomplish
<?php
if( $_SERVER['REQUEST_METHOD']=='GET' && isset( $_GET['buyer_first_name'],$_GET['buyer_last_name'],$_GET['buyer_email'],$_GET['order_id'] ) ){
header( "location: www.mydomain.com/query.php?k=test&action=add&r={$_GET['order_id']}&n={$_GET['buyer_email']}" );
}
?>
Upvotes: 0
Reputation: 387
header("location: www.mydomain.com/query.php?k=test&action=add&r=$orderid&n=$email");
If you use header('location... make sure nothing is visible on the page, otherwise you'll get a "headers already sent, output started...." error.
Upvotes: 0