简体   繁体   English

将PHP会话(+引用数据)脚本转换为ASP.NET

[英]Convert PHP session (+ referral data) script to ASP.NET

This is a PHP script I use to get the referring website for each new visitor to my site. 这是一个PHP脚本,用于为我的网站的每个新访问者获得推荐网站。

If the visitor came from Google, I get the keyword they used to find the site. 如果访问者来自Google,我会得到他们用来查找站点的关键字。

This data is stored in the session then included along with the data from the contact form when an enquiry is sent. 此数据存储在会话中,然后在发送查询时与联系表单中的数据一起包含在内。 This allows clients with little knowledge of analytics to track converting keywords. 这样一来,对分析知识很少的客户就可以跟踪转换关键字。

I need to convert this PHP to work on a site that uses .aspx pages. 我需要将此PHP转换为可在使用.aspx页的网站上工作。 After researching asp.net for several hours, I feel like I still don't have a clue where to start! 在研究了asp.net几个小时后,我觉得我仍然不知道从哪里开始!

<code>
    <?php
    session_start(); // start up your PHP session!

    if (empty($_SESSION['google'])) {
    // if session is empty, take the referer
    $thereferer = strtolower($_SERVER['HTTP_REFERER']);

    // see if it comes from google
    if (strpos($thereferer,"google")) {
    // delete all before q=
    $a = substr($thereferer, strpos($thereferer,"q="));
    // delete q=
    $a = substr($a,2);
    // delete all FROM the next & onwards
    if (strpos($a,"&")) {
        $a = substr($a, 0,strpos($a,"&"));
    }   
    // we have the key phrase
    $_SESSION['google'] = urldecode($a);
    $_SESSION['referer'] = 'Google';
    }
    }

    if (empty($_SESSION['referer'])) {
    $_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
    }
    ?>
</code>

I'd really appreciate a point in the right direction with this. 我真的很欣赏与此有关的正确方向的观点。

Thanks. 谢谢。

You need to read up on the HttpRequest and HttpResponse classes. 您需要阅读HttpRequestHttpResponse类。 More specifically, the Request.ServerVariables collection, the Request.Cookies object, and the Response.Cookies object. 更具体地说,是Request.ServerVariables集合, Request.Cookies对象和Response.Cookies对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM