How to get URL parameter and redirect after

Question

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.


Show source
| url   | php   | html   | forum   | url-redirection   2017-01-06 18:01 2 Answers

Answers ( 2 )

  1. 2017-01-06 18:01

    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);
    ?>
    
  2. 2017-01-06 18:01

    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
    ?>
    
◀ Go back