Extract Text from HTTP referer

I am using the following code to show the referer link any page on my website. How can i modify the code so that it only shows part of the link. i.e if my website url is www.example.com/?s=printing i only want it to extract printing. And this should only happen if the format is www.example.com/?s=aaa and not if the format is anything else like www.example.com/printing.

Code:

<?php 
session_start();
if ( !isset( $_SESSION["origURL"] ) )
$_SESSION["origURL"] = $_SERVER["HTTP_REFERER"]; 
echo $_SESSION["origURL"] 
?>

Related posts

2 comments

  1. I figured it out and the following code works:

    <?php 
        session_start();
        if ( !isset( $_SESSION["origURL"] ) )
        $_SESSION["origURL"] = $_SERVER["HTTP_REFERER"]; 
        $mysearchterm = $_SERVER["HTTP_REFERER"]; 
        $whatIWant = substr($mysearchterm, strpos($mysearchterm, "=") +1);    
        echo  $whatIWant;
    
    ?>
    
  2. Values that are send to a page as part of a link are stored by default in the $_GET variable. Your URL is using s=printing. This means the name of the property is s and the value of the property is printing

    Instead of all the string search actions you could use

    if ( isset($_GET['s']) ) $whatIWant = $_GET['s'];
    

Comments are closed.