简体   繁体   English

通过多个页面跟踪访客的最简单方法是什么?

[英]What's the easiest way to keep tracking a visitor through multiple pages?

I have users coming from both organic and paid search. 我的用户来自自然搜索和付费搜索。

organic users land on page.php , paid users land on page.php?source=paid . 随机用户登陆page.php ,付费用户登陆page.php?source=paid

A PHP variable on page.php would change according the source string, to help me identify where the user initially came from, for example, if he purchase something on my site right from the same page, I would have an indication. page.php上的PHP变量将根据source字符串进行更改,以帮助我确定用户最初来自何处,例如,如果他直接从同一页面上在我的网站上购买了商品,则会有提示。

The problem: 问题:

I have multiple pages in my website. 我的网站上有多个页面。 once a paid user decides to navigate to another page such as page2.php , the indicating variable won't work, as he navigated to page2.php , and not to page2.php?source=paid . 一旦付费用户决定导航到另一个页面(例如page2.php ,指示变量将不起作用,因为他导航到page2.php而不是page2.php?source=paid

So one possible messy solution, would be to drag the string all over the website, by placing on every link, an IF/ELSE that would insert at the end of all the href in the page, a ?source=paid string, in any case that the user initially landed with the ?source=paid string. 因此,一种可能的混乱解决方案是,通过在每个链接上放置一个IF/ELSE ,将字符串拖到整个网站上,该IF/ELSE将插入页面中所有href的末尾,一个?source=paid字符串,用户最初使用?source=paid字符串登陆的情况。

But, is there another option? 但是,还有其他选择吗? I suppose there's a way to do this with cookies? 我想有办法用Cookie做到这一点吗? but I have never dealt with cookies, and rather not to, unless it's easy. 但是我从来没有处理过cookie,除非很简单,否则我不会。

Thanks 谢谢

This is exactly what sessions are for: 这正是会话的目的:

Sessions are a simple way to store data for individual users against a unique session ID. 会话是根据唯一的会话ID为单个用户存储数据的简单方法。 This can be used to persist state information between page requests. 这可用于在页面请求之间保留状态信息。 Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data. 会话ID通常通过会话Cookie发送到浏览器,并且该ID用于检索现有会话数据。

To solve this I would recommend you to use Sessions. 为了解决这个问题,我建议您使用Sessions。

On the first page you need to set the session variable with something like this: 在第一页上,您需要使用以下内容设置会话变量:

<?php>
session_start();
if isset($_GET['source']) {$_SESSION['source'] = $_GET['source'];}

and the rest of your first page goes here..

?>

On the other pages you can recall the sessionvariable like this: 在其他页面上,您可以像这样调用session变量:

<?php>
session_start();
if ($_SESSION['source'] == 'paid')
{ paid version}
else 
{unpaid version}

?>

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

相关问题 用&#39;替换&#39;\\ n&#39;最简单的方法是 <br> &#39;? - What's the easiest way to replace '\n' with '<br>'? 使用带有MySQL和PHP的Google Map API显示多个位置的最简单方法是什么? - What's the easiest way to display multiple locations using Google Map API with MySQL and PHP? 实现在线订单跟踪数据库的最简单方法 - Easiest way to implement an online order tracking database 用PHP重定向到上一页的最简单方法是什么? - What's the easiest way to redirect to the previous page with PHP? 检查字符串是否为bcrypt哈希的最简单,最快捷的方法是什么? - What's the easiest and quickest way to check if a string is a bcrypt hash? 将Java Servlet添加到WAMP配置的机器中最简单的方法是什么? - What's the easiest way to add Java servlets to a WAMP configured machine? 根据另一个下拉列表填充下拉列表的最佳和最简单的方法是什么 - What's the best and easiest way to Populate a dropdown based on another dropdown 解析这样的PHP字符串最简单的方法是什么 - what's the easiest way to parse a PHP string like this 用 PHP 的 mysqli 做准备好的语句的正确和最简单的方法是什么? - What is the correct and easiest way to do prepared statements with PHP's mysqli? 在PHP中加载一组文字数据的最简单方法是什么? - What's the easiest way to load a set of literal data in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM