Forum Moderators: phranque

Message Too Old, No Replies

iscookieenabled checking through htaccess

Very urgent help needed

         

AjiNIMC

7:06 am on Mar 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

This is the process,
Step1: A new person comes to the site, we check whether BlahBlahCookie exists or not using htaccess, if not then direct the user to createcookie.php page.

Step2: createcookie.php page creates the cookie and redirects to the requested page.

Step3: System checks and finds the cookie and delievers the requested page.

Problem: Now if cookie is disabled then Step1 checks the cookie and takes the person to createcookie.php. And in step 2 person is redirected to requested page without creating a cookie. So the person comes back to step1(as the cookie is not there) and there is an infinite loop.

Solution: For normal users I can show a message(directing to a different page, defined in htaccess above the cookie check statements) saying you need your cookies enabled to access the site. (Which I will take to do that, as a lot of people do not know what cookie means).

Major problem: What happens to bots, they will never be able to create cookie and access my pages?

Please help me with this,
1) How can I check whether the access is from a bot or a human inside htaccess?

Thanks in advance,
AjiNIMC

jdMorgan

12:39 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A very simple method:

RewriteCond %{HTTP_USER_AGENT} Googlebot/¦msnbot/¦Yahoo(\!\ Slurp¦Seeker¦-Vertical) [NC]
RewriteRule ^index\.php$ /index_robot.php [L]

To make this more robust would require that you create and maintain a list of all current robot IP addresses.

Change all broken pipe characters above to solid pipe characters before use; Posting on this board modifies them.

Jim

AjiNIMC

1:37 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jim, this is what I did yesterday.
Is there a way to check whether cookie is enabled or disabled?
Can we create a cookie using htaccess?

Thanks again for the help,

Regards
AjiNIMC

jdMorgan

2:07 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can create a simple cookie with mod_rewrite IF you are using Apache 2.x or later.

However, just like any other cookie, it cannot be detected until the next HTTP request from the client.

Remember that a cookie is 'set' by the server sending the response to the current client request and including the set cookie response header. The cookie (if accepted) is then stored on the client hard drive. After the cookie is set, the client then sends it (in the HTTP request headers) with every subsequent request to the server that set it. Therefore, you cannot verify a cookie within the context of the same HTTP request that set it.

Jim

AjiNIMC

8:19 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



However, just like any other cookie, it cannot be detected until the next HTTP request from the client.

Yeah, very true.

How can I solve this problem? I need to check whether a person has his/her browser cookie's enabled or disabled.

Step3: System checks and finds the cookie and delievers the requested page.

This is basically redirecting to a prefered sub-domain based on IP2country mapping.

Thanks Jim

Regards,
AjiNIMC

DeveloperMind

11:20 am on Mar 16, 2006 (gmt 0)

10+ Year Member



Thanks Jim

The answer you have given helped me too.
And I believe that you can help me again. I got stuck with htaccess as usual.

Now the problem I am facing is, how can I check if REFEREL_URL is from the same HTTP_HOST?

Like there is a page [abc.com...] having link to [abc.com...]

I want to check if the user is coming to [abc.com...] from [abc.com...] or from some external domain. In other words I want to check whether this page is referred from internal pages or external ones.

Also can you please help me learn setting a variable in htaccess and using it with a ReWriteCond.

Thanks in advance.
DeveloperMind

jdMorgan

4:56 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AjiNIMC,

OK, I'll have a go:

1) First page check for pre-existing cookie. If set, skip to step 4.
2) Else set a new cookie, redirect to second page.
3) Second page checks for cookie: If cookie set, continue to step 4. If not set, either use session-info-querystring-appended-to-URLs-method, or ask user to allow cookies.
4) User has cookie: End.

Jim