<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1027630" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1027630</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/cookie-detecting-and-redirecting-script-wanted#comment-1164171</link>
    <description> &lt;p&gt;Do you have the option of using server-side scripting like PHP? This task would me much easier accomplished that way.&lt;/p&gt;
&lt;p&gt;Using client-side scripting for this can be easily defeated, either intentionally or unintentionally, and server-side scripting also has the advantage of being much more transparent.&lt;/p&gt;
&lt;p&gt;For example, a simple setup could be as follows:&lt;br /&gt;
[in the .htaccess for your web root]&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;RewriteEngine on&lt;br /&gt;RewriteRule !^index.php /index.php [L]&lt;/code&gt;&lt;/div&gt;&#039;&lt;br /&gt;
[in index.php]&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $default_file &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= \&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;index.html\&quot;; // this file will be returned when the user requests directories&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; session_start();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;agree_button&#039;] == \&quot;agree\&quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;user_agrees&#039;] = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; header(\&quot;Location: /\&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;user_agrees&#039;])&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt; ... &lt;br /&gt;&amp;lt;form action=\&quot;test.php\&quot; method=\&quot;post\&quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=\&quot;submit\&quot; name=\&quot;agree_button\&quot; value=\&quot;agree\&quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt; ... &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; list(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;) = explode(\&quot;?\&quot;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;REQUEST_URI&#039;]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(ereg(\&quot;/$\&quot;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; .= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$default_file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(empty(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$default_file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$fd&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = @fopen(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;DOCUMENT_ROOT&#039;].&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;,\&quot;rb\&quot;))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Error&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;Error&amp;lt;/h1&amp;gt;&amp;lt;b&amp;gt;Couldn&#039;t access the requested file&amp;lt;/b&amp;gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$buf&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = fread(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$fd&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;,1024))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$buf&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;This assumes a couple of things:&lt;br /&gt;
1) You&#039;re using Apache (who doesn&#039;t nowadays?)&lt;br /&gt;
2) You can use .htaccess files (most can)&lt;br /&gt;
3) You have mod_rewrite loaded (this is rather common)&lt;br /&gt;
4) You can use PHP.&lt;/p&gt;
&lt;p&gt;If you can meet those assumptions, then the above script is pretty easy to use. Just put it in your web root, and each and every request will be checked to see if the user has agreed to your terms or whatever. If the user hasn&#039;t accepted the terms, it displays some html (modify it to your needs) containing a form which it processes. If the user has accepted the terms, it fetches the required file, and if this is impossible, it prints an error message (customize this as well). The user never sees the script&#039;s presence again after they&#039;ve agreed (at least until their PHP session cookie gets deleted) and passing on a url will not defeat it either.&lt;/p&gt;
&lt;p&gt;The only downsides to using this are the fact that PHP must be invoked on every request, incurring a slight overhead, and the fact that regular Apache errordocuments can&#039;t be used, but neither of these are a major issue IMO.&lt;/p&gt;
 </description>
     <pubDate>Wed, 12 Jan 2005 20:53:36 +0000</pubDate>
 <dc:creator>netman w00t</dc:creator>
 <guid isPermaLink="false">comment 1164171 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
