<?xml version="1.0" encoding="UTF-8"?>    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>Restricting Viewer Access to Logged In Users in 2.53</title>
        <link>https://interactivetools.com/forum/forum-posts.php?Restricting-Viewer-Access-to-Logged-In-Users-in-2_53-78675</link>
        <description></description>
        <pubDate>Mon, 10 Aug 2026 21:48:06 -0700</pubDate>
        <language>en-us</language>
        <atom:link href="https://interactivetools.com/forum/forum-posts.php?rss=1&amp;Restricting-Viewer-Access-to-Logged-In-Users-in-2_53-78675" rel="self" type="application/rss+xml" />

                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230646#post2230646</link>
          <description><![CDATA[<p>Hi Jason,</p>
<p>Sorry for the delay.</p>
<p>I get no errors when logged in either as admin or non-admin with the following at the top of the page:</p>
<p><code>&lt;?php<br />     if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />   // load viewer library<br />   $libraryPath = 'cmsAdmin/lib/viewer_functions.php';<br />   $dirsToCheck = array('/hsphere/local/home/a12345/my_site.com/','','../','../../','../../../');<br />   foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}<br />   if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }<br />   <br /> //Get the current CMS users details<br />   $CMS_USER = getCurrentUserFromCMS(); <br />   <br />   //redirect the browser if no user is currently logged into the back end<br />   if (!@$CMS_USER['num']){ <br />     session_unset();<br />     redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />     exit;<br />   }<br />   <br /> ?&gt;</code></p>
<p>And this in the body:</p>
<p><code>&lt;?php if( $CMS_USER['isAdmin']): ?&gt;<br /> Code for admins...<br />       &lt;?php elseif( !$CMS_USER['isAdmin']): ?&gt; :?&gt;<br /><br />      Sorry, you're logged in but you're not an admin...<br /><br />      &lt;?php else :?&gt;&lt;?php else :?&gt;<br /><br />        Sorry, based on the login credentials you used, you don't have the authority to access this page. &lt;br /&gt;<br />       &lt;br /&gt;<br />       To log in with the appropriate credentials, &lt;a class="special" href="<a href="/cmsAdmin/admin.php?action=logoff">http://www.my_site.com/cmsAdmin/admin.php?action=logoff</a>"&gt;Click Here to Log Out&lt;/a&gt;, then return to this page and log in again.&lt;br /&gt;<br />       <br />       &lt;?php endif ?&gt;<br /></code></p>
<p>Again, thanks for all your help,</p>
<p>Jerry Kornbluth</p>]]></description>
          <pubDate>Sun, 19 May 2013 09:31:22 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230646#post2230646</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230478#post2230478</link>
          <description><![CDATA[<p>Hi Jerry,</p>

<p>Can you let me know what error you get when you log in as a non admin?</p>

<p>Thanks</p>]]></description>
          <pubDate>Mon, 06 May 2013 12:09:37 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230478#post2230478</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230364#post2230364</link>
          <description><![CDATA[<p>Greg Thomas has done it again...</p>
<p>He came up with this solution. He said,<br /><br />“For some reason the server was creating two different sessions depending on if you are logged in at <a href="/">http://your_site.com/</a> or <a href="">http://www.your_site.com.</a> As the log off link was to www.your_site.com this was causing an issue if the user had logged in at the non www version. I've got around the problem by adding a rule to your htaccess file that redirects all site visitors to your_site.com. I've also added the session_unset to the if statement that checks if the user is logged in, as this should completely destroy the session.”<br /><br />The .htaccess rule is:</p>
<p><code><br /> # Redirect www urls to non-www<br /> RewriteEngine on<br /> RewriteCond %{HTTP_HOST} ^www\.your_site\.com [NC]<br /> RewriteRule (.*) <a href="/$1">http://your_site.com/$1</a> [R=301,L]<br /></code></p>
<p>The viewer code including the session_unset code is:</p>
<p><code>&lt;?php<br />     if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />   // load viewer library<br />   $libraryPath = 'cmsAdmin/lib/viewer_functions.php';<br />   $dirsToCheck = array('/path_to_your_server/','','../','../../','../../../');<br />   foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}<br />   if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }<br />   <br /> //Get the current CMS users details<br />   $CMS_USER = getCurrentUserFromCMS(); <br />   <br />   //redirect the browser if no user is currently logged into the back end<br />   if (!@$CMS_USER['num']){ <br />     session_unset();<br />     redirectBrowserToUrl("<a href="/cmsAdmin/admin.php?redirectUrl=">http://your_site.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />     exit;<br />   }<br />  ?&gt; </code></p>
<p>In the body of my viewer to separate access to the code for users and the code for admins:</p>
<p><code>&lt;?php if( $CMS_USER['num']): ?&gt;<br />  &lt;a class="special" href="<a href="/cmsAdmin/admin.php?action=logoff">http://your_site.com/cmsAdmin/admin.php?action=logoff</a>"&gt;Click Here to Log Out&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;<br /> Code for any user...<br />       &lt;?php endif ?&gt;<br /> &lt;br /&gt;<br />  &lt;?php if( $CMS_USER['isAdmin']): ?&gt;<br /> Code for admins only...<br /> &lt;?php endif ?&gt;</code></p>
<p>Hope Greg's solution helps someone else.</p>
<p>Jerry Kornbluth</p>]]></description>
          <pubDate>Thu, 25 Apr 2013 12:25:22 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230364#post2230364</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230349#post2230349</link>
          <description><![CDATA[<p>Thanks Greg.</p>
<p>I've submitted a 2nd level request.</p>
<p>the file that I've been testing with is publicitya.php</p>
<p>Jerry Kornbluth</p>]]></description>
          <pubDate>Tue, 23 Apr 2013 12:41:24 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230349#post2230349</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230344#post2230344</link>
          <description><![CDATA[<p>Hi Jerry,</p>
<p>Could you fill out a second level support request for me so that I can login to the CMS area and recreate the issue? You can find the form here:</p>
<p><a href="https://www.interactivetools.com/support/email_support_form.php" rel="nofollow">https://www.interactivetools.com/support/email_support_form.php</a></p>
<p>Thanks!</p>
<p>Greg</p>]]></description>
          <pubDate>Tue, 23 Apr 2013 11:34:33 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230344#post2230344</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230320#post2230320</link>
          <description><![CDATA[<p>Hi Greg,</p>
<p>Sorry for the delay.</p>
<p>That added line didn't destroy the login session</p>
<p>I've attached the page code and the 2 cookies that are generated when a non-Admin user logs in. cms_5159ca3da2187_loginsession and cms_5159ca3da2187_PHPSESSION.</p>
<p>Thanks,</p>
<p>Jerry Kornbluth</p>]]></description>
          <pubDate>Mon, 22 Apr 2013 13:13:24 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230320#post2230320</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230315#post2230315</link>
          <description><![CDATA[<p>Hi Jerry,</p>
<p>Could you add some code to destroy the session data if the user isn't logged in your if statement?</p>
<p><code> &lt;?php if($CMS_USER['isAdmin']): ?&gt;<br />   code for admins only...<br />&lt;?php else :?&gt;<br /><span style="color:#339966;">   &lt;?php unset($_SESSION['otherSessonVariable']); ?&gt;</span><br />   Sorry, based on the login credentials you used, you don't have the authority to access this page.<br />   &lt;br /&gt;<br />   &lt;br /&gt;<br />   To log in with the appropriate credentials, &lt;a class="special" href="<a href="http://www.elleschorrphotography.com?action=logoff" rel="nofollow">http://www.elleschorrphotography.com?action=logoff</a>"&gt;Click Here to Log Out&lt;/a&gt;, then return to this page and log in again.&lt;br /&gt; &lt;/span&gt;<br />&lt;?php endif ?&gt;</code></p>
<p>If this doesn't work, could you post all of your code so far so I can see what is being stored in the non-admin session?</p>
<p>Cheers</p>
<p>Greg</p>]]></description>
          <pubDate>Mon, 22 Apr 2013 11:28:14 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230315#post2230315</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230301#post2230301</link>
          <description><![CDATA[<p>Hi Greg,<br /><br />I see what you mean by your last question.<br /><br />I have some pages that are open to anyone who can login as a user, but some that are restricted to admins only.<br /><br />If the entire page is to be hidden from non-admins, I surrounded the restricted code with an if statement as shown in the code below.<br /><br />*** The only issue that seems to remain is that when I use the logoff code, &lt;a href="<a href="http://www.elleschorrphotography.com/cmsAdmin/admin.php?action=logoff" rel="nofollow">http://www.elleschorrphotography.com/cmsAdmin/admin.php?action=logoff</a>"&gt;Click Here to Log Out&lt;/a&gt;, the previous non-admin login cookie does not get destroyed, and when I return to that page I’m still seeing the restricted message. If I delete the cookie, then things go back to normal.<br /><br />Any thoughts?<br /><br />Thanks,<br /><br />Jerry Kornbluth</p>
<p><code>&lt;?php if($CMS_USER['isAdmin']): ?&gt;<br /><br /> code for admins only...<br /><br />  &lt;?php else :?&gt;<br />      <br /> Sorry, based on the login credentials you used, you don't have the authority to access this page.<br /><br /> &lt;br /&gt;<br /> &lt;br /&gt;<br /> To log in with the appropriate credentials, &lt;a class="special" href="<a href="http://www.elleschorrphotography.com?action=logoff" rel="nofollow">http://www.elleschorrphotography.com?action=logoff</a>"&gt;Click Here to Log Out&lt;/a&gt;, then return to this page and log in again.&lt;br /&gt; &lt;/span&gt;<br /><br /> &lt;?php endif ?&gt;</code></p>
]]></description>
          <pubDate>Sat, 20 Apr 2013 07:03:54 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230301#post2230301</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230299#post2230299</link>
          <description><![CDATA[<p>Hi Greg</p>
<p>It is perfect!<br /><br />It is also independent of activation on False or True.</p>
<p>Thanks again!</p>
<p>Djulia</p>]]></description>
          <pubDate>Fri, 19 Apr 2013 13:27:35 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230299#post2230299</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230293#post2230293</link>
          <description><![CDATA[<p>Hi Jerry,</p>
<p>Sorry, but I'm not 100% sure where you want non admin users to be taken if they don't have access to the page, should they be redirected to the admin area? Should people who aren't logged in also be redirected to the CMS area? If you're trying to send non admin users to the CMS area to log in, this should work:</p>
<p><code>  //Get the current CMS users details<br />  $CMS_USER = getCurrentUserFromCMS();<br />  //redirect the browser if no user is currently logged into the back end<br />  if (!@$CMS_USER['isAdmin']){<br />     redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php</a>");<br />    exit;<br />  }</code></p>
<p>Thanks!</p>
<p>Greg</p>]]></description>
          <pubDate>Fri, 19 Apr 2013 11:23:46 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230293#post2230293</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230278#post2230278</link>
          <description><![CDATA[<p>Hi Greg,</p>
<p>Sorry that this is becoming so complex and time consuming.</p>
<p>I think we're getting further off base with my NON membership plugin issue. (Djulia had the membership plugin issue, and I'll follow up on that later)</p>
<p>The code you offered a few posts back:</p>
<p><code>//Get the current CMS users details<br />   $CMS_USER = getCurrentUserFromCMS(); <br />   <br />   //redirect the browser if no user is currently logged into the back end<br />   if (!@$CMS_USER['num']){ <br />     redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />     exit;<br />   }</code></p>
<p>Works fine.</p>
<p>It's only when I try to restrict to admins only, by changing</p>
<p><code>if (!@$CMS_USER['num'])</code></p>
<p>To</p>
<p><code>if (!@$CMS_USER['isAdmin'])</code></p>
<p>and then log in as a<span style="text-decoration:underline;"> non-admin</span> user that I get back into the loop issue. (logging in as an Admin works fine)</p>
<p>If I use your latest idea, the user is taken back into the back end which is not what I'm trying to do.</p>
<p>Hope that clarifies the problem.</p>
<p>Thanks,</p>
<p>Jerry Kornbluth</p>]]></description>
          <pubDate>Thu, 18 Apr 2013 11:01:16 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230278#post2230278</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230274#post2230274</link>
          <description><![CDATA[<p>@ Jerry,</p>
<p>I think I've found out what the problem is, it looks as if  your code is creating an infinite redirect loop. publicity.php is forwarding to the cmsAdmin area, then CMS Builder is detecting the redirectUrl variable in the URL, and redirecting back to publicity.php, which then redirects back to the CMS Admin area, etc. I would remove the redirectUrl variable from the publicity.php redirect:</p>
<p><code>  //Get the current CMS users details<br />  $CMS_USER = getCurrentUserFromCMS(); <br />  <br />  //redirect the browser if no user is currently logged into the back end<br />  if (!@$CMS_USER['num']){ <br />    redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php</a>");<br />    exit;<br />  }</code></p>
<p>@Djulia,</p>
<p>I've done some quick testing in version 2.53. Have you got the WSM_SEPARATE_LOGIN global set to true in your website membership plugin? If not you can change it on line 33 of websiteMembership.php:</p>
<p><code>$GLOBALS['WSM_SEPARATE_LOGIN']            = true;         // set this to allow you to login to the website and CMS simultaneously as different users</code></p>
<p>The test code below should output the front end and CMS user array details:</p>
<p><code>&lt;?php header('Content-type: text/html; charset=utf-8'); ?&gt;<br />&lt;?php<br />  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */<br />  <br />  // load viewer library<br />  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';<br />  $dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');<br />  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}<br />  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }<br /><br /><br />  $CMS_USER = getCurrentUserFromCMS(); <br /><br />  showme($CMS_USER);<br /><br />  showme($CURRENT_USER);</code></p>
<p>Thanks!</p>
<p>Greg</p>]]></description>
          <pubDate>Thu, 18 Apr 2013 09:53:45 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230274#post2230274</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230271#post2230271</link>
          <description><![CDATA[<p>@Jerry -- Excuse me, I had not understood!<br /><br />@Greg -- The function does not seem to work with 2.53.<br />I also tried to add "global $CURRENT_USER", but without success (no array()).<br /><br />Do you have an idea?</p>
<p>Thanks!</p>
<p>Djulia</p>]]></description>
          <pubDate>Wed, 17 Apr 2013 23:47:57 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230271#post2230271</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230267#post2230267</link>
          <description><![CDATA[<p>Hi Greg,</p>
<p>Thanks for discovering that. It seems to work.</p>
<p>One more question...</p>
<p>When I try to restrict access to admins by changing !@$CMS_USER ['num'] to !@$CMS_USER ['isAdmin'], if I log in as an admin the redirect works as it's supposed to, but if I log in as a non Admin it crashes with the same error as before.</p>
<p>Any thoughts?</p>
<p>Thanks,</p>
<p>Jerry Kornbluth</p>
]]></description>
          <pubDate>Wed, 17 Apr 2013 16:38:22 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230267#post2230267</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230266#post2230266</link>
          <description><![CDATA[<p>Hi Jerry, </p>
<p>Sorry for a delay in the reply. </p>
<p>I've just discovered there is a new function you can use to get the current CMS user, and it works if you don't have the website membership plugin:</p>
<p><code>  //Get the current CMS users details<br />  $CMS_USER = getCurrentUserFromCMS(); <br />  <br />  //redirect the browser if no user is currently logged into the back end<br />  if (!@$CMS_USER['num']){ <br />    redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />    exit;<br />  }<br /></code></p>
<p>So the getCurrentUserFromCMS function returns an array that looks similar to the $CURRENT_USER array, but contains the CMS users information. </p>
<p>Thanks!</p>
<p>Greg</p>]]></description>
          <pubDate>Wed, 17 Apr 2013 16:12:22 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230266#post2230266</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230265#post2230265</link>
          <description><![CDATA[<p>Thanks Djulia,</p>
<p>I'm not using website membership on these sites</p>
<p>I'll keep that in mind though.</p>
<p>Jerry Kornbluth</p>

]]></description>
          <pubDate>Wed, 17 Apr 2013 15:07:53 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230265#post2230265</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230263#post2230263</link>
          <description><![CDATA[<p>Hi Jerry,</p>
<p>If you use version 2.53, you must check that the variable $GLOBALS [“WSM_SEPARATE_LOGIN”] is on "false" (in websiteMembership).</p>
<p><code>&lt;?php<br />   if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />   require_once "/path_to_your/cmsAdmin/lib/viewer_functions.php";<br />   if (!isset($CURRENT_USER['username'])) { header("Location: /"); exit; }<br /> ?&gt;</code></p>
<p>Hope that helps!</p>
<p>Djulia</p>]]></description>
          <pubDate>Wed, 17 Apr 2013 14:16:03 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230263#post2230263</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230262#post2230262</link>
          <description><![CDATA[<p>Hi Greg,</p>
<p>Any new insights on this?</p>
<p>Jerry Kornbluth</p>]]></description>
          <pubDate>Wed, 17 Apr 2013 13:52:49 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230262#post2230262</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230239#post2230239</link>
          <description><![CDATA[<p>Hi Greg,</p>
<p>Sorry, but That didn't change anything. the result is identical.</p>
<p>I thought $CURRENT_USER was only valid when using the membership plugin. I guess not.</p>
<p>Jerry</p>]]></description>
          <pubDate>Tue, 16 Apr 2013 11:23:05 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230239#post2230239</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230238#post2230238</link>
          <description><![CDATA[<p>Hi Jerry,</p>
<p>Are you still having issues with the page redirecting on some browsers?</p>
<p>I hadn't noticed earlier, but CMS Builder empties out the $_SESSION array and stores all user data in $CURRENT_USER for security reasons. So to detect if a user is logged in or not I would do this:</p>
<p><code>   if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />  // load viewer library<br />  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';<br />  $dirsToCheck = array('/hsphere/local/home/a887307/elleschorrphotography.com/','','../','../../','../../../');<br />  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}<br />  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }<br /><span style="color:#339966;">  if (!@$CURRENT_USER['num']){ </span><br />    redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />    exit;<br />  }</code></p>
<p>So as the $CURRENT_USER['num'] is a field that can't be changed, I've used it to detect if a user is logged in or not. </p>
<p>Thanks!</p>
<p>Greg</p>]]></description>
          <pubDate>Tue, 16 Apr 2013 11:05:11 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230238#post2230238</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230237#post2230237</link>
          <description><![CDATA[<p>Sorry Greg,</p>
<p>With the code you recommended (below) I get the same error.</p>
<p>The protected page is <a href="http://elleschorrphotography.com/publicity.php" rel="nofollow">http://elleschorrphotography.com/publicity.php</a></p>
<p>If I'm lot logged in, the URL is <a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=/publicity.php" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=/publicity.php</a> and I get redirected to the login page.</p>
<p>The URL that comes up after login is still <a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=/publicity.php" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=/publicity.php</a> but I get the same error as before.</p>
<p>I've tried a few sites with the same result.</p>
<p>Jerry</p>
<p>&lt;?php<br /> <br /> if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />  // load viewer library<br />  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';<br />  $dirsToCheck = array('/hsphere/local/home/a887307/elleschorrphotography.com/','','../','../../','../../../');<br />  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}<br />  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }<br />  if (!@$_SESSION['username']) { <br />    redirectBrowserToUrl("<a href="http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />    exit; }<br />?&gt;</p>]]></description>
          <pubDate>Tue, 16 Apr 2013 10:47:36 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230237#post2230237</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230233#post2230233</link>
          <description><![CDATA[<p>Hi Jerry,</p>
<p>The most likely cause is that the page has already sent the headers in the newer version CMSB for some reason, and so can't change the header to send the page to a new location.</p>
<p>Try changing your code to this:</p>
<p><code>&lt;?php<br />  if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />  require_once "/path_to_your/cmsAdmin/lib/viewer_functions.php";<br />  if (!@$_SESSION['username']) { <br />    redirectBrowserToUrl("<a href="http://mydomain.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://mydomain.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']);<br />    exit; <br />  }<br />?&gt;</code></p>
<p>The redirectBrowerToUrl function detects if the page headers have already been sent, and uses HTML or JavaScript to redirect the browser instead if required.</p>
<p>Let me know if this doesn't work.</p>
<p>Thanks!</p>
<p>Greg</p>]]></description>
          <pubDate>Tue, 16 Apr 2013 09:18:35 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230233#post2230233</guid>
        </item>
                <item>
          <title>Restricting Viewer Access to Logged In Users in 2.53</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2230228#post2230228</link>
          <description><![CDATA[<p>Hi All,<br /><br />I’ve been restricting viewer access to logged in users only using the following code:<br /><br />&lt;?php <br />if (!defined('START_SESSION')) { define('START_SESSION', true); }<br />require_once "/path_to_your/cmsAdmin/lib/viewer_functions.php";<br />if (!@$_SESSION['username']) { header("Location: <a href="http://mydomain.com/cmsAdmin/admin.php?redirectUrl=" rel="nofollow">http://mydomain.com/cmsAdmin/admin.php?redirectUrl=</a>" . $_SERVER['REQUEST_URI']); exit; }<br />?&gt;<br /><br />But after upgrading from 2.17 to 2.53, that code returns a “page not redirecting properly error “ in FF and a “cannot display web page” in IE<br /><br />Any suggestions on the changes required for the new version?<br /><br />Thanks,<br /><br />Jerry Kornbluth</p>]]></description>
          <pubDate>Tue, 16 Apr 2013 05:18:56 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2230228#post2230228</guid>
        </item>
              </channel>
    </rss>
  