Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter BugfreeSystems

    (@bugfreesystems)

    It’s me again,

    with a solution for the feature request “autologin with specific referer host name(s)”.

    Now it is possible to autologin into the blog frontend, if the user is comming from a specific website.

    I extended the function doHeadActions() in file wp-content/plugins/password-protect-wordpress/pluginCallbacks.php after this lines of code:

    function doHeadActions()
    {
      $isEnabled = $this->_settings()->fetchSetting( "enabled" )->getValue();
        if( $isEnabled == "off" ) {
          //protection is disabled
          return;
      }

    with my new code:

    // autologin by referer host
      $referer = @$_SERVER['HTTP_REFERER'];
      $checkRefererHosts = array('www.source.net');
      if (isset($referer)) {
        $aParsedUrl = parse_url($referer);
        if (isset($aParsedUrl['host'])) {
          $refererHost = $aParsedUrl['host'];
          if (in_array($refererHost, $checkRefererHosts)) {
            //refresh logged in cookies
            $this->setCookie();
            return;
          }
          else {
            $isLoggedIn = apply_filters( $this->_slug( "isLoggedIn" ), false );
          if (false === $isLoggedIn ) {
    	do_action( $this->_slug( "displayLoginPage" ) );
    	exit;
          }
        }
      }

    It works fine, but It’s not update safe.
    Couldn’t it be a new feature in further releases of the plugin?
    The referer hosts (checkRefererHosts) should be defined in settings of the plugin.

    Greets TJ

    FYI, you’re missing a “{” at the end of line 14.

    Perhaps you can help me with my need, which is to allow Facebook’s crawler to see my content without a password. I tried the following, right where your code starts (instead of yours), with no luck:

    $userAgent = "";
    		$userAgent = @$_SERVER['HTTP_USER_AGENT'];
    		if (strpos($userAgent, 'facebookexternalhit') !== FALSE) {
    			//refresh logged in cookies
    			this->setCookie();
    		    return;
    		}
    		else {
    			$isLoggedIn = apply_filters( $this->_slug( "isLoggedIn" ), false );
    		}
    		if (false === $isLoggedIn ) {
    			do_action( $this->_slug( "displayLoginPage" ) );
    			exit;
    		}

    I even tried just a:


    this->setCookie();
    return;

    to try and make everything go around login…and it’s not working. So what obvious point am I missing?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Autologin with referer IP address’ is closed to new replies.