Detect if a user visited page coming from same site - php

I need to know if a user visited the webpage by clicking on a link from the same website. I can use $_SERVER['HTTP_REFERER'] and check if the domain is the same. But HTTP_REFERER is not always set.
I must detect the difference between visiting a page via own website and coming from an external website (or direct visit). This must be able over and over again, meaning that if a user leaves the site and come back through a search result, I again must be able to detect this.
I thought about setting a session, but than I can't detect a second visit within the session lifetime. Also don't see an option for setting a cookie.
What other options do I have?

I think you should use Database(MySQL) to save the HTTP_REFERER each time for every visit from a specific IP and for a particular date.
You can check the time difference between the two records (like in some minutes) that an IP has accessed and can get the records if a user leaves and come back again to the website. This way you can track the logs for each visitor like how many times a visitor access the website.
Hope this way you can manage the desired output for your application.

Related

Use of website cookies based on the account logged in

Brainstorming for a feature right now, looking for advice and tips.
If this is possible to do, I would like to have a search bar save what the user has written and save the search (if there are results found) as a cookie. There will be up to three searches saved where the newest one that is accepted replaces the oldest one. My concern is that am I able to save these search cookies uniquely on every user account?
My plan is the following:
User searches
check if the search yields results.
save as cookie if a search is successful
Display on website
the purpose of the cookie is to show a product in our site homepage based on the searches
Save on individual accounts
the cookies used here should not transfer outside the account used at that time, if a new user logs
in, there will be no cookies.
if a user that searches logs back, the previous cookies will still be present and display products
accordingly.
My thoughts are this will be similar to my remember me login cookies that saves them with:
setcookie ("login_email",$_POST["email"],time()+ 3600);
setcookie ("login_password",$_POST["password"],time()+ 3600);
The website where is is going to be made is using PHP.
I would like some advice on what logic should I use on the code, thank you for reading and looking forward to any responses.

how to display different page on different request on my website

I want to show different home page when user visit every time my site, means new html page on every new visit or repeat visit.
When user open a site the first time he/she see x.html next time y.html next z.html and so on.
Please help me
You may use cookies to store information on user (client) side that he/she has already visited your site. Please refer to: http://php.net/manual/en/features.cookies.php for info about cookies in PHP. It requires that user accepts cookies in the browser. In the cookie you may keep info about already seen pages.
Yet another way is to store such information on server side but it may be risky because it is not obvious how to identify unique user on server side (combination of IP + browser - may not always work - users from the same private network may provide the same externally visible IP).
The last solution that comes to my mind is to force user to login to your page. Then, upon login, you may count a number of times the given user (identified by username) has been on your page and provide diffent page each time.
Create a script that will choose a different page at random.
Store the pages in an array
$pages = array('page1.php','page2.php','page3.php');
Get random number
$rand = mt_rand(0,2);
Use that random number to choose page from array
$rand_page = $pages[$rand];
Then show the page to the user
include($rand_page);

Best way to pass session information to another domain to track conversions?

Building a web application that is 90% API-based, meaning it will be hosted on the client's website (eg clientdomain.com). When API calls are made, we are creating and storing a session ID on the client's domain, and we store all the stats on their activity while a visitor browses their site.
But there's one part of our application that is hosted on our servers, because it has to be secure (eg client.ourdomain.com). Visitors will click a link from the client's website to ours.
What's the best way to somehow tell the application on our domain that this is an active session with session id XXXXXXX? I've thought of a few options:
Check sessions table for IP and timestamp within a certain range. Obviously this would not be a good option because some large groups and organizations use the same IP.
Pass the session ID as a GET variable, downside is these links may be shared or saved for later use.
Pass as POST var using a form button
Use some kind of redirect variable dynamically created that is only good for a small time frame (i.e. 10 or 30 minutes) and then deleted
Am I missing a possible solution?
Our ultimate goal is to track a visitor through goal completion so we can show conversion rate, bounce rate, etc. To do that we absolutely have to match up a visitor from clientdomain.com to client.ourdomain.com.
Thanks in advance!
Your first option is the answer, SessionID + IP = Unique.
User A and User B may have the same IP but their session id is different.
Fifth:
go
redirect-to-secure.php:
header('Location: http://client.ourdomain.com/?clientSession=' . session_id());
On client.ourdomain.com, if you detect clientSession GET param, save it to session and redirect to page without clientSession. This way browser won't remember this url.

Unique user signature

I need to be able to detect if a used already visited a particular page.
I can set a cookies at their initial visit. I can also store some environment, such as IP, browser, OS, perhaps even language and create some string, like MD5 to compare against current visitor's environment.
Is there another method I should consider?
I work with PHP.
This isn't well defined enough for me to understand why just using cookies wouldn't satisfy this problem. A cookie has a domain and path that you can set on the server for each page they visit. As they visit each page you can look at those two settings to figure out if they have the cookie set on their browser or not and hence they have visited the page. You really don't have to get anymore sophisticated than that if all you want to know is did they visit the page before now.

how to maintain user preferences across multiple domains in PHP

i am developing a multilingual site in expression engine. and i am using different domains for different languages versions of site eg: www.site.en, www.site.jp, etc.
now i want to track the visitors language preference that is i want to find out which of these domains was visited by that user/system(no user login feature) in the last.
suppose i visit www.site.com and i switch to www.site.jp and close my browser.
so next time when the user visits any of these domains i want to redirect the user to the domain(www.site.jp in this case) he visited last.
The problem is that i can't set a cookie for another domain.
Neither do i have a user login feature.
Nor do i want to user third party cookies coz it won't be reliable system.
Right before redirect user to www.site.jp, you should set a cookie in www.site.com. Therefore, when user visit again in www.site.com the cookie is readable in your PHP script, and you can redirect again.
If user visit directly into www.site.jp, you need not to bother that, cause the site is already in Japanese.
OR
always redirect to www.site.com/setcookie?lang=xx,
before any domain switching and right after cookie set, do the necessary redirect
So, in theory, www.site.com always keep a cookie for the last selected language, and you can use that to redirect to www.site.xx
OR
instead using multiple domain name, using seconds level directory for separation, like
www.site.com/en
www.site.com/jp
www.site.com/zh

Categories