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:
<?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)"?
Oops, I goofed up, the code I have currently is:
<?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" ...
= 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.
Ok, I understand the = versus ==, so I changed my footer code to:
<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.
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.
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:
<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...
$user_id probably doesn't exist. Use the USER_ID constant as I mentioned earlier.
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:
<?php
$user_id=(USER_ID);
if ($user_id == 5) {
echo "YOUR MESSAGE HERE";
}
?>
Works like a charm!
Thanks again.
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<?php
if (USER_ID == 5) {
echo "YOUR MESSAGE HERE";
}
?>