0

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..

1

6 Answers 6

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0
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.

Comments

0

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']}" );

    }
?>

Comments

0

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");

Comments

0

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);
?>

Comments

0
$querystring = "www.websitedomain.com/redirect.php?".$_SERVER['QUERY_STRING'];
header('location:'.$querystring);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.