Reputation: 17
I don't have much experience with php or sql so I may be missing something really basic. My main goal is that if a first file is visited and then a second file is visited you will be able to access that second file. However if you don't visit the first file you are denied access. I have an HTML file which is meant to set $_SESSION[upgrade]
to 1. I use accountify and it "extends php's session support" so this might be a accountify related question. Also a session is already running because of accountify. (Link To Accountify) This is the complete file:
<?php
require '/home/u760887416/public_html/accountify/login.php';
if (!isset($_SESSION['upgrade'])) {
$_SESSION['upgrade'] = 1;
};
echo("<p>You were upgraded. <br>Redirecting...</p>");
//this is a test:
if($_SESSION['upgrade'] = 1) {
echo("<p>complete</p>");
};
?>
After it is set to 1, in a different file I want if $_SESSION['upgrade'] = 1
then it loads some code. Here is the code:
<?php
require '/home/u760887416/public_html/accountify/login.php';
if($login->loggedIn AND $_SESSION['upgrade'] = 1) {
?>
//code to run...
<?php
} else {
?>
//more code to run
<?php
}
?>
The problem is that after I load the first file and go to the second (it doesn't matter if I reset the session, create a new one or use a different computer) it always runs the else
code. I've spent way too much time on this and can't figure it out. Please tell me if I did not supply enough information to figure this out.
Upvotes: 0
Views: 86
Reputation: 679
Use ==
instead of =
in your if statements.
Using =
SETS the value of $_SESSION['upgrade']
to 1, not compares it to 1.
Change if declaration of your first file like that:
if($_SESSION['upgrade'] == 1) {
echo("<p>complete</p>");
};
Also I recommend using &&
instead of AND
operator. Your if in the second file should look like this:
if($login->loggedIn && $_SESSION['upgrade'] == 1) {
?>
//code to run...
<?php
} else {
?>
//more code to run
<?php
}
?>
Upvotes: 3