Jump to content

[SOLVED] If on *this* page, do *this*


amclean

Recommended Posts

I've kinda written myself into a corner.  I've got an include file that decides the behavior and appearance of everything in this system I'm developing.  Basically I'm trying to make it so that if a user hasn't created a profile, when they login, they have no choice but to fill one out before continuing.

In the include file, i made an If statement checking if the requirement isn't reached, redirect the browser to that page.  I had considered setting it just on the logon page, but the user should have no choice but to go there no matter where they try to go, and it's just easiest to set it in one place than many.

The problem is, the profile page layout and appearance is also set by the same include file.  Which means it also tries to redirect (to itself, forever).

What I need is a way to say

If (status==needprofile)
     {
          if (!"currenturl"=="profile.php")
               {
                   header('Location: profile.php');
               }
     }

 

Hopefully that makes sense.

 

Thanks in advance once again.

 

Link to comment
https://forums.phpfreaks.com/topic/139930-solved-if-on-this-page-do-this/
Share on other sites

Page name only:

 

If (status==needprofile)
          if (curPageName()=="profile.php")
                   header('Location: profile.php');

function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

echo "The current page name is ".curPageName();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.