0

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.

1 Answer 1

3

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
  } 
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.