Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this PHP include not working?
    text
    copied!<p>I'm trying to create a logout link that gets included into an authorized area.</p> <p>The authorized area looks like this:</p> <pre><code>&lt;?php require_once '../../includes/initialize.php'; if(!$Session-&gt;is_logged_in()) { redirect_to('login.php'); } $user = $User-&gt;find_by_id($Session-&gt;user_id); ?&gt; &lt;!-------------- START OF LOGOUT LINK --------------&gt; &lt;?php if (isset($_GET['logout'])) { $Session-&gt;logout($user); $Logger-&gt;logout($user); redirect_to('login.php'); } ?&gt; &lt;p style="float: right;"&gt;&lt;a href="?logout=true"&gt;Logout&lt;/a&gt;&lt;/p&gt; &lt;!-------------- END OF LOGOUT LINK --------------&gt; &lt;p&gt;Welcome &lt;?php echo $user-&gt;first_name; ?&gt;, you are now logged into the admin area.&lt;/p&gt; </code></pre> <p><strong>The above code works just fine!</strong></p> <p>But when I change it so the logout link is an include, I get an error. This is what I put in my include file called logoutlink.php:</p> <pre><code>&lt;?php if (isset($_GET['logout'])) { $Session-&gt;logout($user); $Logger-&gt;logout($user); redirect_to('login.php'); } ?&gt; &lt;p style="float: right;"&gt;&lt;a href="?logout=true"&gt;Logout&lt;/a&gt;&lt;/p&gt; </code></pre> <p>I then include it into my authorized area as such:</p> <pre><code>&lt;?php require_once '../../includes/initialize.php'; if(!$Session-&gt;is_logged_in()) { redirect_to('login.php'); } $user = $User-&gt;find_by_id($Session-&gt;user_id); ?&gt; &lt;!-------------- START OF LOGOUT LINK --------------&gt; &lt;?php include '../../includes/logoutlink.php'; ?&gt; &lt;!-------------- END OF LOGOUT LINK --------------&gt; &lt;p&gt;Welcome &lt;?php echo $user-&gt;first_name; ?&gt;, you are now logged into the admin area.&lt;/p&gt; </code></pre> <p>I get the following errors:</p> <p><strong>Notice: Undefined variable: Session...</strong></p> <p>&amp;</p> <p><strong>Fatal error: Call to a member function logout() on a non-object in...</strong></p> <p>Can someone explain what I'm missing? Thanks in advance for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload