The conditions in your IF statements are assignments, not equality checks. Because a non-empty string in PHP is a truthy value, the return value from the assignment statement will be true (executing the first IF statement body always).
To get around this common mistake of using assignments instead of equality checks, some people use yoda conditions, where the string literal is used as the left-hand operand, and the variable to check against is used as the right-hand operand. This will error out when a single equals is used (for an assignment), since you cannot assign a value to a literal:
Yes, as @StarLion said, the http_referer header is generally eschewed because it is unreliable (since it can be turned off in a userâs browser, effectively rendering your code snippet useless). Perhaps as an alternative solution, you could use a session to capture the previous page, and then check to see firstly if that session exists on the next page, and if so then compare its value using your two IF statements above.
I will forget about using the HTTP_REFERRER thing in a bit, but for now am trying to get the redirecting working.
It isnât working as of this moment and cant figure out if im missing something. but am using
Is anything at all being output by the script before it gets to this point? Even a single character of output would prevent headers being able to be written as the headers need to be written before the content.
As felgall said, Define âisnt workingâ. Blank screen may indicate a syntax error; being redirected to the wrong page is a thing. Try echoing âMooâ after the last line of your code; you have an If, an Else If⌠but nothing if neither of the conditions are met. You may be running into the problem youâre skipping - are you sure that http_referrer is set?