Title: Hasaccess problems
Last modified: November 9, 2021

---

# Hasaccess problems

 *  Resolved [alex8872](https://wordpress.org/support/users/alex8872/)
 * (@alex8872)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/hasaccess-problems/)
 * Hi guys,
 * I hope you are well. My developer has added the code below to unlock paid articles
   from visitors via Google and Google news etc. That way people that are new to
   our site can read one free article. If they then click on a link to another article
   or visit our site directly, they will see locked articles and have a chance to
   sign up.
 * Before we added Autoptimze the code had no problems. But with Autoptimze, sometimes
   the articles are locked, and sometimes they are not locked so it seems that our
   code is randomly working. How can we make Autoptimze ignore that code?
 * We use Autoptimze for this specific function “Aggregate all linked CSS files?”
   if not the google crawler will not load all of our CSS files. We also pay for
   CriticalCSS.
 * So we really need our code and Autoptimze to work.
 * We also use Cloudflare APO and have our entire site on their system. But we can
   see that just clearing the cache via Autoptimze will be enough to get the code
   working.
 * Here is the code so you what I mean.
 *     ```
       if (preg_match('/google/i', $_SERVER['HTTP_USER_AGENT']))
       	    {
       			$hasaccess = true;
       	    }
       	    elseif (preg_match('/google/i', $_SERVER['HTTP_REFERER'])){
       			$hasaccess = true;
       		}
       		elseif (preg_match('/ampproject/i', $_SERVER['HTTP_REFERER'])){
       			$hasaccess = true;
       		}
       		else
       		{
       		    // you can do something here
           	}
       ```
   
 * I hope this makes sense.
 * Thanks
    Alex
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhasaccess-problems%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/hasaccess-problems/#post-15051799)
 * Hey Alex;
    I’m afraid I have no idea how autoptimize would interfere there :-/
   the `$hasaccess` is not a variable used or overwritten by AO (and AO does not
   touch the user agent or referrers).
 * The most likely culprit would be page caching at some level (a caching plugin
   or maybe at the level of your host maybe). A lot of page caching plugins also
   act on Autoptimize’s cache (which contains optimized JS/ CSS) being cleared, 
   so that could explain why the issue goes away (temporarily) when the AO cache
   is cleared?
 * frank

Viewing 1 replies (of 1 total)

The topic ‘Hasaccess problems’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/hasaccess-problems/#post-15051799)
 * Status: resolved