NathanDrake Posted January 21, 2011 Share Posted January 21, 2011 Hi, I'm trying to change an OpenSource software that is using PHP code, I'm somewhat new to PHP and am wanting to learn more on it, but I'm having trouble a couple of things. On rightcolumn.tpl, I include another file called login_rightside.tpl where it is a login box. What I want to do is if the user clicks "Register" and gets taken to "signup.php" then that login box on "login_rightside.tpl" should disappear. So basically my pseudocode is this: if (current page = signup.php do nothing else {include file="login_leftside.tpl"} end if My problem is how to tell it that the current page is signup.php. If anyone can provide some help, I'd appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/225148-question-on-how-to-check-if-a-user-is-on-a-certain-page/ Share on other sites More sharing options...
hoogie Posted January 21, 2011 Share Posted January 21, 2011 something like this if ($_SERVER['PHP_SELF'] != "signup.php") { include('login_leftside.tpl'); } You might want to test the output of the PHP_SELF first to make sure it's what you want. It might be something like /path/to/signup.php instead. To test it you can simply put this somewhere in your signup.php file, and then load it in your web browser and see what it says. echo $_SERVER['PHP_SELF']; Quote Link to comment https://forums.phpfreaks.com/topic/225148-question-on-how-to-check-if-a-user-is-on-a-certain-page/#findComment-1162840 Share on other sites More sharing options...
NathanDrake Posted January 21, 2011 Author Share Posted January 21, 2011 Thanks for your help, I put the code on signup.php page and it shows /signup.php I tried using the code you provided, and it actually makes a lot of sense and was very helpful. But since I'm be calling it from "rightcolumn.tpl", the PHP code didn't work. I tried the following but it still didn't work, it still displayed the login box regardless of what page I was in. {if $smarty.server.php_self != 'signup.php'} {include file="login_rightside.tpl"} {else} Testing code {/if} What's interesting is that I then tried: {if $smarty.server.php_self == 'signup.php'} {include file="login_leftside.tpl"} {else} Testing code {/if} And it actually displayed the text "Testing code" on the right column, but it displayed that on every page (index.php, search.php etc), so I have no idea why that's happening... Quote Link to comment https://forums.phpfreaks.com/topic/225148-question-on-how-to-check-if-a-user-is-on-a-certain-page/#findComment-1162851 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2011 Share Posted January 21, 2011 If the value of $_SERVER['PHP_SELF'] was /signup.php, you would need to test for '/signup.php'. If the actual path can be different, you might want to consider just using the filename portion of the value. See the basename function. Quote Link to comment https://forums.phpfreaks.com/topic/225148-question-on-how-to-check-if-a-user-is-on-a-certain-page/#findComment-1162945 Share on other sites More sharing options...
hoogie Posted January 22, 2011 Share Posted January 22, 2011 Yeah, looks like you need the slash in there. Try this: if ($_SERVER['PHP_SELF'] != "/signup.php") { include('login_leftside.tpl'); } Quote Link to comment https://forums.phpfreaks.com/topic/225148-question-on-how-to-check-if-a-user-is-on-a-certain-page/#findComment-1163375 Share on other sites More sharing options...
NathanDrake Posted January 22, 2011 Author Share Posted January 22, 2011 Thanks guy, the problem is solved. Quote Link to comment https://forums.phpfreaks.com/topic/225148-question-on-how-to-check-if-a-user-is-on-a-certain-page/#findComment-1163410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.