Jump to content

Question on how to check if a user is on a certain page


NathanDrake

Recommended Posts

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.

Link to comment
Share on other sites

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'];

 

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.