duanlie2709 2011-11-11 23:42
浏览 45

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

This is a PHP script I use to get the referring website for each new visitor to my site.

If the visitor came from Google, I get the keyword they used to find the site.

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. After researching asp.net for several hours, I feel like I still don't have a clue where to start!

<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.

  • 写回答

1条回答 默认 最新

  • duankuiyuant3940 2011-11-11 23:59
    关注

    You need to read up on the HttpRequest and HttpResponse classes. More specifically, the Request.ServerVariables collection, the Request.Cookies object, and the Response.Cookies object.

    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图