How to get URL parameter and redirect after

2k views Asked by At

Please I need help with how to write php code to get a URL parameter from and redirect to another page after. My URL looks something like this http://mywebsite.com/login.php?referrer=forum

The parameter I am interested in is the referrer=forum

I need this because i am trying to integrate a forum into my website which i am almost done with except for the single sign on(SSO) feature which allows the forum to use the register and login system i have already created for my website.

Thanks.

2

There are 2 answers

0
Phil Poore On

Something like this:

<?php
// get parameter from URL params
$referrer = $_GET['referrer'];

// redirect to another URL, including the referrer above
header('Location: http://someotherwebsite.com/?referrer=' . $referrer);
?>
4
Jaymin Panchal On

You can store that parameter value in variable and pass in the link or you can use Session to use that variable across the multiple page.

<?php 
    session_start();
    $_SESSION['referrer'] = $_GET['referrer'];
?>

And then in second page just use it from the session

<?php
    session_start(); 
    echo $_SESSION['referrer']; // use it as per your requirement
?>