Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    show image if user is logged in

    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 Code:
    <?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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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?
    Last edited by Fou-Lu; 10-21-2004 at 10:03 AM.

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That would be a client-side problem with the rendering or your html.

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Fou-Lu
    • The $_COOKIE['usernamecookie'] != "" is not nessessary. Use if (!$_COOKIE['usernamecookie']) instead.
    I would use isset() and empty() to check if a variable exists or is empty. Using !$varable would give you a notice.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •