Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Adding information (user specific messages) to header/footer?  (Read 4504 times)

0 Members and 1 Guest are viewing this topic.

Jax2

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 23

I have my gallery bridged with postNUKE.

When an unregistered visitor to my site clicks on "Gallery" from postnuke, it opens the gallery in a new window and they are automatically logged on as "Guest".

I have the permissions set up so they cannot do anything other than view the current pictures, however, I want to explain to them why this is, and how they can upload their own, which means they need to register on my site.

Here is where I am running into the problem:

The user_id for "Guest" is 5.
What I have tried to do on the footer is:
Code: [Select]
<?php
if ( $user_id "Guest" ) {
echo 
"Please note that guests cannot uploads files. Please sign up as a new user <a href='http://www.shotthis.com'>HERE</a> to create your album!";
}
?>

However, this is displaying the message to everyone, logged in or not.

How do I set this up so that only GUEST see's the message?

Any help would be appreciated.

(Also, I guess an even easier question is, what code do I use in my header/footer to display the users name, such as "Welcome ($user_name)"?

« Last Edit: July 28, 2007, 08:34:24 am by Nibbler »
Logged

Jax2

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 23
Re: Adding information (user specific messages) to header/footer?
« Reply #1 on: July 28, 2007, 06:54:56 am »

Oops, I goofed up, the code I have currently is:
Code: [Select]
<?php
if ( $user_id "5" ) {
echo 
"Please note that guests cannot uploads files. Please sign up as a new user <a href='http://www.shotthis.com'>HERE</a> to create your album!";
}
?>

user_id="5", not "guest" ...
Logged

Nibbler

  • Guest
Re: Adding information (user specific messages) to header/footer?
« Reply #2 on: July 28, 2007, 06:56:49 am »

= means assignment, ie $x = 5;
== means comparision, ie. if ($x == 5) { ... }

The user name is stored in the USER_NAME constant, the user id is stored in the USER_ID constant and is normally 0 for unlogged users.
Logged

Jax2

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 23
Re: Adding information (user specific messages) to header/footer?
« Reply #3 on: July 28, 2007, 07:16:41 am »

Ok, I understand the = versus ==, so I changed my footer code to:

Code: [Select]
<div align="center">
<?php
if ($user_id "5") {
echo 
"Please note that guests cannot uploads files. Please sign up as a new user <a href='http://www.shotthis.com'>HERE</a> to create your album!";
}
?>

</div>

And it DOES show the message, the only problem is, it's showing it to EVERYONE... I log on as admin, and I see it, log back on as "Guest" and I see it.

How can I get it to show this message ONLY when "Guest" (user id 5) is logged in?

Sorry, kind of new at this, php anyhow.
Logged

Nibbler

  • Guest
Re: Adding information (user specific messages) to header/footer?
« Reply #4 on: July 28, 2007, 07:19:33 am »

I just explained that. You are using a single equals which means assignment. Your code sets $user_id to 5 and then displays the message. What you want to do is to compare $user_id to 5 so you need to use double equals.
Logged

Jax2

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 23
Re: Adding information (user specific messages) to header/footer?
« Reply #5 on: July 28, 2007, 07:28:00 am »

Ok, I appreciate you trying to help me, so please don't get frustrated... lol

It's still not working.

I have footer.php, changed the code around some more to test it out, here is what I have:

Code: [Select]
<div align="center">
<?php
if ($user_id == "5") {
echo 
"Working";
}
echo (
$user_id);
?>

test
</div>

When I upload this and check the page as "Guest", all I see is "TEST". the echo ($user_id); doesn't show the user ID, and the "Working" doesn't show up.
This doesn't show for anyone else either, admin, or other names.

So what am I doing wrong? Does the footer.php not get the $user_id info from the index.php? Do I have to have a call to mysql to get the user_id in the footer?

I could just leave a message on there that everyone sees, but I'd really prefer not to have to take this route...

Logged

Nibbler

  • Guest
Re: Adding information (user specific messages) to header/footer?
« Reply #6 on: July 28, 2007, 07:30:21 am »

$user_id probably doesn't exist. Use the USER_ID constant as I mentioned earlier.
Logged

Jax2

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 23
Re: Adding information (user specific messages) to header/footer?
« Reply #7 on: July 28, 2007, 07:56:05 am »

Ok, got it working, thanks for the help. Here is what I did incase anyone else wants to know how to add a user name / custom message:

Code: [Select]
<?php
$user_id
=(USER_ID);
if (
$user_id == 5) {
echo 
"YOUR MESSAGE HERE";
}
?>


Works like a charm!

Thanks again.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Adding information (user specific messages) to header/footer?
« Reply #8 on: July 29, 2007, 12:11:31 pm »

Thanks for returning and posting your solution. It doesn't make sense though to define a var and then use it only for comparison, as you can perform the comparison with the constant just as well. Subsequently, the code you should use is
Code: [Select]
<?php
if (USER_ID == 5) {
  echo 
"YOUR MESSAGE HERE";
}
?>
Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 20 queries.