...

View Full Version : show image if user is logged in



jemand
10-21-2004, 09:21 AM
hi
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

Fou-Lu
10-21-2004, 09: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?

jemand
10-21-2004, 10: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

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

marek_mar
10-21-2004, 02: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.

Fou-Lu
10-21-2004, 02: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum