Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How to replace an image when logged into the account?

  1. #1
    Join Date
    May 2010
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default How to replace an image when logged into the account?

    1) Script Title: How to replace an image when logged into the account?

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...taticmenu3.htm

    3) Describe problem:

    Hi Everyone,

    I am making a website which is in PHP.

    Could anyone help me and advise me on how to replace an image (Sing-up button) with another image when the user's are logged in?

    For example: The sign-up button is showing in the header.php and when the users logged in I want that image to change to another image!!

    Please view the image here: http://img508.imageshack.us/i/samplel.jpg/

    is there any piece of code that I could place in my header.php in order to do that?

    Any help will be much appreciated.

    Thank you.




    Moderator note: this was originally posted as 3 separate threads. They have all been merged, so that's why reading the posts below is confusing. And that's a good reason NOT to post the same question more than once!
    Last edited by djr33; 05-16-2010 at 06:50 PM. Reason: duplicate postings merged

  2. #2
    Join Date
    May 2010
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default How to replace an image when logged into the account?

    [Duplicate post, content removed. Same question as above.]
    Last edited by djr33; 05-16-2010 at 06:53 PM.

  3. #3
    Join Date
    May 2010
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default How to replace an image when logged into the account?

    [Duplicate post, content removed. Same question as above.]
    Last edited by djr33; 05-16-2010 at 06:53 PM.

  4. #4
    Join Date
    May 2010
    Location
    Dhaka, Bangladesh
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi,
    There is a very simple way to do that. While you are authenticating a user I am assuming that you are using session to save the authenticated user's record. I am assuming that you are storing a value in session like $_SESSION[user_id]

    then in your sidebar you can use a simple logic:
    PHP Code:
    if(isset($_SESSION[user_id]))
      echo 
    '<img src="abc.jpg">';
    else
     echo 
    '<img src="signup.jpg">'
    Have a try... best of luck!
    Last edited by naoshad; 05-16-2010 at 05:32 PM. Reason: addition

  5. The Following User Says Thank You to naoshad For This Useful Post:

    crf121359 (05-17-2010)

  6. #5
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Without seeing your members script, something like this, with the logged-in variable passed to the session;

    Code:
    <?php if (isset($_SESSION['logged_in_user'])) { ?>
    
    <!-- any HTML -->
    <img src="images/hello_member.jpg" alt="">
    
    <?php } else { ?>
    
    <!-- any HTML -->
    <img src="images/login_prompt.jpg" alt="">
    
    <?php } ?>
    For something more specific though, we'd need to see your php code.

    I do something similar for one of my own sites;
    Guests get the boring banner, login panel and 3 mini-quick icons (left side) while members get the character banner and 6 mini-quick icons (left side). As webmaster, I also get an extra menu button on the right for administration.

    Logged out -


    Logged in -


    Hope that helps

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. It's best to replace the entire thing (including the link, for example) so that the new image doesn't go to the same place (I'm assuming you have the sign up image as a link).

    2. Naoshad, using an index name directly [user_id] will give a warning if you don't have "notice" errors turned off. It parses as a constant of the same name, so it WILL work, but it's not correct. Use ['user_id'] instead to avoid errors and have more efficient code.



    Here's a slightly adjusted version. Adjust as needed:
    PHP Code:
    if(isset($_SESSION['user_id']))
      echo 
    '<img src="welcomeuser.jpg">';
    else
     echo 
    '<a href="signup.php"><img src="signup.jpg"></a>'

    Using the html directly (outside of PHP) is actually a great way to do it, so just borrow from Beverley's post above, but also remember it's probably best to include the <a> tag there.



    Additionally, since you've posted this in several places (and now it's all merged), there's another complicating factor: the script this is all based on. The answers here are general and not for the specific script.
    It should still generally apply, but you may have to adjust some or use PHP to dynamically generate the Javascript because it's a little different using that.
    Last edited by djr33; 05-16-2010 at 06:56 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. The Following User Says Thank You to djr33 For This Useful Post:

    crf121359 (05-17-2010)

  9. #7
    Join Date
    May 2010
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default How to replace image when logged in?

    Hi guys,

    Thanks for the replies.
    Unfortunately I am still struggling to get this done!!

    Here is a copy of the header.php:

    Code:
    <div id="wrapper_header"> 
    
    
    
    <div class="logo_s"><a href="<?=_BASEURL_?>/" title="<?=_TITLE_?>"><img src="<?=_BASEURLMEDIA_?>/logo.png" alt="My website" /></a><div class="beta"></div></div>
    
    <div id="log_pane"> 
    
    <? if($_SESSION['uid'] ==''){  ?>
    
    <div class="corner_l"><div class="corner_c">
    
    
    
    <form method="post" action="<?=_BASEURL_?>/login.php" name="frm11">
    
    <div><input type="text" name="email" value="<?=_EML_ID11_?>" class="inputtext" onclick="_delete_login_fields(this, '<?=_EML_ID11_?>', this.value);"/></div>
    
    <div><input type="password" name="password"  value="<?=_PWS_11111_?>" class="inputtext" onclick="_delete_login_fields(this, '<?=_PWS_11111_?>', this.value);" /></div>
    
    <div><input type="submit" name="submit" value=" " class="submit" /></div>
    
    </form>
    
    <div class="reg">
    
    <a href="<?=_BASEURL_?>/register/index.html">Register</a> | <a href="<?=_BASEURL_?>/forgot-your-password/index.html">Forgot Your Password</a></div></div></div>
    
    <? }else{?>
    
    <div class="corner_l"><div class="corner_c">
    
    <div class="sfl tm15px lm30px">Welcome</div>
    
    <div class="normaltextblackbold11 lm5px sfl"> <?=get_uname($_SESSION['uid'])?></div>
    
    
    
    
    
    <?
    
     $uname=mysql_fetch_array(mysql_query("select id,uname,image,no_bids from user where id=".$_SESSION['uid']));
    
    ?>
    
    
    
            <div class="tm10px ">    Available My website Credits:</div> 
    
    <div id="user_current_bids" class="normaltextblackbold11 lm5px sfl"> <?=$uname['no_bids'];?> </div>
    
    
    
    <script language="javascript">
    
    function find_no_bids(strURL)
    
    {
    
    
    
     	var xmlHttpReq_num = false;
    
        var self_num = this;
    
        // Mozilla/Safari
    
        if (window.XMLHttpRequest) {
    
            self_num.xmlHttpReq_num = new XMLHttpRequest();
    
        }
    
        // IE
    
        else if (window.ActiveXObject) { 
    
            self_num.xmlHttpReq_num = new ActiveXObject("Microsoft.XMLHTTP"); 
    
        }
    
    	
    
        self_num.xmlHttpReq_num.open('POST', strURL, true);
    
        self_num.xmlHttpReq_num.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
        self_num.xmlHttpReq_num.onreadystatechange = function() {
    
            if (self_num.xmlHttpReq_num.readyState == 4) 
    
    		{
    
                document.getElementById("user_current_bids").innerHTML=self_num.xmlHttpReq_num.responseText;
    
            }
    
        }
    
        self_num.xmlHttpReq_num.send('');
    
    
    
    	setTimeout("find_no_bids('ajax_num_bids.php')",2000);
    
    }
    
    
    
    setTimeout("find_no_bids('ajax_num_bids.php')",2000);
    
    </script>
    
    
    
    
    
    
    
    
    
    <a class="header2right smalla1bww " href="<?=_BASEURL_?>/logout/index.html"><?=_LOGOUT11_?></a></div></div>
    
    <? }?>
    
    <div class="corner_r"></div>
    
    <div class="shadow"></div>
    
    <div id="log_secrh"><div class="log_secrh"><form name="headerSearchForm" id="headerSearchForm" action="<?=_BASEURL_?>/search.php" onSubmit="return searchproduct();" method="get"><input type="text" id="keyword" name="keyword" value="Search..." class="inputtext" onclick="_delete_login_fields(this, 'Search...', this.value);" /></form></div></div>
    
    </div>
    
    
    
    
    
    
    
    
    
    <div class="tab_show_effect_sh">
    
    <div class="tab_show_effect">
    
    <div id="toptab_ef">
    
    <ul class="show_tab">
    
    <li class="home"><a href="<?=_BASEURL_?>/">&nbsp;</a></li>
    
    <? if($_SESSION['uid']!=''){?>
    
    <li class="acc"><a href="<?=_BASEURL_?>/myauctions/index.html">&nbsp;</a></li>
    
    <? }
    
    else{?>
    
    <li class="acc"><a href="<?=_BASEURL_?>/login/index.html">&nbsp;</a></li>
    
    <? }?>
    
    
    
    <li class="cat"><a href="<?=_BASEURL_?>/allcategories/index.html">&nbsp;</a></li>
    
    <li class="auc"><a href="<?=_BASEURL_?>/seeallauctions/index.html">&nbsp;</a></li>
    
    <li class="how"><a href="<?=_BASEURL_?>/howitworks/index.html">&nbsp;</a></li>
    
    <li class="news"><a href="<?=_BASEURL_?>/newsdetail/index.html">&nbsp;</a></li>
    
    <li class="green"><a href="<?=_BASEURL_?>/faq_buyers.php">&nbsp;</a></li>
    
    <li class="contact"><a href="<?=_BASEURL_?>/contact/index.html">&nbsp;</a></li>
    
    </ul>
    
    
    
    </div>
    
    </div>
    
    </div>
    <DIV STYLE="position:absolute; marging-top:1px; margin-left:720px; width:239px; height:199px; font-family:Arial; font-size:10pt;"><img src="img/sign.png" width="250" height="199" border="0" usemap="#Map" style="float:right"/>
    <map name="Map" id="Map"><area shape="rect" coords="74,116,176,170" href="http://www.my website.com/register/index.html" target="_self" />
    </map></DIV>
    
    
    
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    
    <script type="text/javascript" src="fadeslideshow.js">
    
    /***********************************************
    * Ultimate Fade In Slideshow v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
    ***********************************************/
    
    </script>
    
    <script type="text/javascript">
    
    var mygallery=new fadeSlideShow({
    	wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    	dimensions: [707, 199], //width/height of gallery in pixels. Should reflect dimensions of largest image
    	imagearray: [
    		["http://www.My website.com/img/1.png", "", "", "My website.com offers a wide range of products. Save up to 98% of RRP prices."],
    		["http://www.My website.com/img/2.png", "Combined shopping & Gaming.", "_new", "Gear Deals, Small Prices... That is what we do..."],
    		["http://www.My website.com/img/3.png"],
    		["http://www.My website.com/img/4.png", "", "", "My website.com offers a wide range of products."] //<--no trailing comma after very last image element!
    	],
    	displaymode: {type:'auto', pause:16000, cycles:0, wraparound:false},
    	persist: false, //remember last viewed slide and recall within same session?
    	fadeduration: 500, //transition duration (milliseconds)
    	descreveal: "ondemand",
    	togglerid: ""
    })
    
    
    
    </script>
    
    <div id="fadeshow1"></div>
    
    <br />
    
    </div>

    Could you please let me know what I have to do to achieve what I am trying to do?


    Cheers.
    Last edited by djr33; 05-16-2010 at 08:56 PM. Reason: Use [code] tags!

  10. #8
    Join Date
    May 2010
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default How to replace image when logged in?

    Hi again,

    I actually forgot to mention that the "sing.png" is what users will see before they logged in and I just want to replace that with "sign2.png" when the users are logged in to their accounts!

    Daniel, I do apologize for duplicated posts, this is my first time that I am sending any posts on forums like this and I am not quite clear on how to use this kind of forums. I will need to get the hang of it.

    Thank you in advance.
    Last edited by crf121359; 05-16-2010 at 09:08 PM. Reason: message to moderator.

  11. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You already seem to be doing the content switch already with your <? if($_SESSION['uid'] ==''){ ?> code so are you saying that what you already have isn't working?

    If it is, you can just follow the same principles.

    If user id is equal to nothing, show this HTML
    <? if($_SESSION['uid'] ==''){ ?>
    <!-- any HTML -->
    <?php } ?>


    If user id is not equal to nothing, show this HTML
    <? if($_SESSION['uid'] !=''){ ?>
    <!-- any HTML -->
    <?php } ?>

  12. The Following User Says Thank You to Beverleyh For This Useful Post:

    crf121359 (05-17-2010)

  13. #10
    Join Date
    May 2010
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default How to replace image!!

    Quote Originally Posted by Beverleyh View Post
    You already seem to be doing the content switch already with your <? if($_SESSION['uid'] ==''){ ?> code so are you saying that what you already have isn't working?

    If it is, you can just follow the same principles.

    If user id is equal to nothing, show this HTML
    <? if($_SESSION['uid'] ==''){ ?>
    <!-- any HTML -->
    <?php } ?>


    If user id is not equal to nothing, show this HTML
    <? if($_SESSION['uid'] !=''){ ?>
    <!-- any HTML -->
    <?php } ?>
    Hi,

    Yes, it is working fine but what I am trying to do is that to change the image "Sign UP" button or sign.png once they are logged in as well.... at the moment when the users are logged in, the sign up button is still there...

    I just want to know how I can do that in that header.php...

    Thank you.
    Kind Regards

Bookmarks

Posting Permissions

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