Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hi,

I am currently working on an internal site for the company I work with, and have found CouchCMS to be excellent to work with for this particular purpose.

My problem has to do with a page, which is embedded whenever the masterpage is accessed without specifying the page id (same as outlined in the Tutorials section).

Each page in my site checks for the 'username' variable to be present, in order to evaluate whether the current user is actually logged in. Apart from this, I also use that variable in a "Welcome" message.

In my embedded page I have places this at the top (before the !DOCTYPE html tag):

Code: Select all
<cms:php>
   session_start();

   global $user;
   if(!isset($_SESSION['username'])){
      header("location:index.php");
   }else{
      $user = $_SESSION['username'];
      echo "User: $user";
   }
</cms:php>


This works perfectly since the username gets printed on screen (from the very last line, which I added as a test).

Now within the actual page I try to display the username like this:

Code: Select all
<p>Welcome <cms:php>print(\"<b>$user</b>\");</cms:php> &nbsp; <a href="logout.php">logout</a></p>


but it seems that the parameter is non-existent at that point. Please help!
Hi and welcome :)

I think adding the global keyword should do the trick.
Please try the following
Code: Select all
<cms:php>global $user; print("<b>$user</b>");</cms:php>

Hope this helps.
@KK Thank you for your reply.

I had already tried that but alas it did not work.

I have since solved the issue, by having the "if" statement wrap around the div I want to populate programmatically (instead of the the whole page, as outlined in the tutorials), in turn this left the section where I am populating the username field alone. So now I can use php outside of the snippet.
I'm glad the problem was resolved.
However, it intrigues me as to why the snippet I posted wouldn't work.
Since I don't have access to your source code, it'd be difficult to know the reason.

Anyways, what is important is that there was a workaround :)

Do let us know if there is anything else we could help with.
Thanks.
I found that strange too, I will try and experiment some more on it in my free time, you know for science!

Anyway keep up the good work, and thank you again!
5 posts Page 1 of 1