Leaving If open for conditional content

I have a website where the content show is dependant on the status of a user vs an array. The authorization is done by a system we cannot control that authorizes all users, our site is only supposed to be available to a small group of users with a certain status.

We have to show an error if not in our group, and load the page if in our group. Our site has 30 content pages which all include the same header, footer, and data info.

I have several includes, the structure is :

Lets load - Content.php

Include - Databases connections - databaseconnect.php
Include - Header - header.php
Open If (in header)
Load actual Content
include footer - footer. php
close if.

My condition works, but I cannot seem to keep the if open through a file end? What am I doing wrong / how should i go about this?

what is your if statement ?

Its hard to say what you need to do without code.

I could say use a session variable on login or a cookie or or if you have a variable like var = admin then do this else do that but hard to understand what you want.

if else can work if loggedin else header location index.page

My code is 3 pages long. We already have the authentication working, that is not an issue, the issue is how to code it in such a way it can span various includes.

Ill write some psydo code:

End of Header.php
$affiliation = GetAuthUserAff();
$authorized = array(“auth1, auth2”);

if (in_array("$affiliation", $authorized))
{

Content.php
Include header.php

Footer.php
}
else { echo “You are not authorized to view this page”;}

Do you understand what I am trying to say? The error is when header.php ends it automatically closes my if statement, which I do not want. I tried a Switch/Case, and it also did not work :frowning:

Urg cannot edit the post. I meant to say we cannot modify the login as it is coded outside out web page though some external login script. We can call variables from it, but we do not set them.

Its too complicated for my little brain to understand.

What I am trying to say is you can make up a variable put it in the database.

I am sort of guesing what you want as I do not understand what you want 100%
if admin
[php]mysql query = blah blah user = admin

$row = fetch ($query)

if ($row[‘user’] == “admin”){
i am admin show my code
}else if ($row[‘user’] == “user”){
show this code
} else {
echo who the hell r u
}[/php]

Yeah thats basically what I have, but the problem is where the code lies. So say I have like 40 pages all these content pages call the same header and footer.

All 40 pages are content protected. So "i am admin show my code " is the entire content of the site. So either I have to copy and paste the same if/else onto 40 pages or it has to go in the header.

So it makes sense to put the if at the end of the header file, right? (because content.php includes header.php as its first line). And then the close of the condition } else {} in the footer. Right?

This doesn’t work however.

it should work that way ok.

What error message do you get ?

are there any other curly braces in the footer ?

I don’t have a development environment, so all I get is a HTTP Error 500, due to an error being on the page.

I think the problem is in the includes, it has to be I just dont understand PHP enough to know that if a file ends does it close the brackets automatically?

The brackets in the footer are correct :frowning:

You can add the error messages yourself

[php]//Report all errors
error_reporting(E_ALL);[/php]

Yeah, that doesnt work. All I get is a server error. I guess my organization doesn’t want random code operating on their server.

Ok totally simplified the code:

testheader.php
[php]<?php
switch ($affiliation) {
case “staff”;

[/php]

test.php
[php]<?php include “header.php”
echo" hello!

";

include “footer.php”
[/php]

testfooter.php
[php]<?php
break;
default;
echo “You are not Authorized to view this content”;
break; }
?>[/php]

Why would you do that?

testheader.php
[php]

<?php if($affiliation != "staff"){ die("You're not authorized to be here!"); } ?>

[/php]

test.php
[php]<?php include “header.php”
echo" hello!

";

include “footer.php”
[/php]

testfooter.php
[php]
footer stuff
[/php]

We have to use an organizational authorization program not coded by us, it authorizes all users (basically since i dont have skill to code one myself with the central directory) but we dont want all users accessing it meaning we need to do some sort of content control.

We have worked out that if it is for a non authorized user, the footer would never load, and so would never load the if, and never close the loop.

We think this is what is happening. But honestly, not sure, very confused. lol.

If you don’t want the footer to load, then do one condition in the footer or body and leave everything else alone. Don’t break up your php.

testfooter.php
[php]
if($affiliation != “staff”){
echo “You’re not staff!”;
} else {
echo “FooterHTML”;
}

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service