View Full Version : show image if user is logged in

10-21-2004, 10:21 AM
i have a little problem
this should show an image if the user is loged in and show other image with a link if the user isnt loged in

} <?php
if ($_COOKIE['usernamecookie'] !="") {
echo('<img src="http://pathtotheimage.jpg">');
}else {
echo('<a href="http://www.thelink.php"><img src="pathtotheimage..jpg"></a>');

problem is it shows only the image with the link no matter if user is loged in or not
thank you for any help

10-21-2004, 10:57 AM
This could be due to several reasons:

There is no $_COOKIE['usernamecookie']. Check to make sure that exists. If there is a cookie set, its possible that its your server, you could try $HTTP_COOKIE_VARS['usernamecookie'].
Information is in a session, not a cookie. Try $_SESSION if this is the case.
The $_COOKIE['usernamecookie'] != "" is not nessessary. Use if (!$_COOKIE['usernamecookie']) instead.
There is no } at the end of your else statement.

Hope this helps you a bit.

Also, why do you have a closed bracket at the top, before the <?php?

10-21-2004, 11:43 AM
There is no } at the end of your else statement.
this was the problem
thank you
but now the new problem is that the image is covered by a viollete line

10-21-2004, 01:29 PM
That would be a client-side problem with the rendering or your html.

10-21-2004, 03:39 PM
The $_COOKIE['usernamecookie'] != "" is not nessessary. Use if (!$_COOKIE['usernamecookie']) instead.

I would use isset() (http://www.php.net/isset) and empty() (http://www.php.net/empty) to check if a variable exists or is empty. Using !$varable would give you a notice.

10-21-2004, 03:58 PM
Point well taken!

I'm so used to scripting without using any cookies or sessions, that my script requires the session or it will restart a new one via functions. Never thought about the error causing.