Extract Text from HTTP referer

混江龙づ霸主 提交于 2019-12-24 15:42:03

问题


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"] 
?>

回答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'];


来源:https://stackoverflow.com/questions/35035882/extract-text-from-http-referer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!