Title: ask2_2008's Replies | WordPress.org

---

# ask2_2008

  [  ](https://wordpress.org/support/users/ask2_2008/)

 *   [Profile](https://wordpress.org/support/users/ask2_2008/)
 *   [Topics Started](https://wordpress.org/support/users/ask2_2008/topics/)
 *   [Replies Created](https://wordpress.org/support/users/ask2_2008/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/ask2_2008/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/ask2_2008/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/ask2_2008/engagements/)
 *   [Favorites](https://wordpress.org/support/users/ask2_2008/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Protect only certain pages/categories](https://wordpress.org/support/topic/protect-only-certain-pagescategories/)
 *  Thread Starter [ask2_2008](https://wordpress.org/support/users/ask2_2008/)
 * (@ask2_2008)
 * [18 years ago](https://wordpress.org/support/topic/protect-only-certain-pagescategories/#post-766250)
 * Here is a solution (hopefully)
    I added a check in the header that redirects 
   users that are not logged in to the login page. The example is for only one protected
   page but I guess its possible to do this in a similar way with more pages.
 * <?php
    # First get the page url $host = $_SERVER[‘HTTP_HOST’]; $self = $_SERVER[‘
   PHP_SELF’]; $query = !empty($_SERVER[‘QUERY_STRING’]) ? $_SERVER[‘QUERY_STRING’]:
   null; $url = !empty($query) ? “[http://$host$self?$query&#8221](http://$host$self?$query&#8221);:“
   [http://$host$self&#8221](http://$host$self&#8221);; # Check if user is logged
   in. If not redirect if ( !is_user_logged_in() && $url == “[http://myprotectedpageadress&#8221](http://myprotectedpageadress&#8221);){
   header(‘Location: [http://myloginpage&#8217](http://myloginpage&#8217);); } ?
   >

Viewing 1 replies (of 1 total)