changing graphics after login

Discussion in 'Customization & add-ons' started by sstark, Oct 27, 2010.

  1. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    I have clickable sign up graphics on my website and am wondering how I would go about having the graphics change after someone is logged in. Obviously, our users don't need to see sign-up graphics. Instead I would like to have graphics that link to various pages on the site.

    I have played around with the session variables and am trying to learn the proper code for instances such as this. Can I use PHP and session variables to do this?
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Take a look here:

    http://manual.amember.com/Integrating_aMember_Pro_with_website

    Specifically something like this should work (untested)
    Code:
    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print '<img src="/path/image1.jpg" >';
    } else { // user is not logged-in
    print '<img src="/path/image2.jpg" >';
    }
    ?>
  3. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    thank you for the response. I am not able to get that to work. I have tried multiple variations with no success. Is there another function besides "print" that needs to be used. Or am I missing something from the statements? When I replaced the image with the following code the page will not load. I assume that is because there is a php error?

    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print "<img src="Images/signup_sidebar.jpg" >
    ";
    } else { // user is not logged-in
    print "<img src="Images/signup_fit_profile.jpg" >"
    }
    ?>



  4. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Only really a beginner php coder but I would have been inclined to do something along the lines of:
    PHP:
    <?php
    $image
    ='image1.jpg';
    if (
    $au=$_SESSION['_amember_user']) $image='image2.jpg'//user is logged-in
    ?>

    <img src=<?php $image ?> width="xxx" height="yyy" alt="" />
     
    I haven't tested it but basically you set $image to the not logged in image and then check if the person is actually logged in. If they are $image is then set to the logged in image. Finally next line displays image using normal html tags.

    image1.jpg obviously refers to the 'not logged in' image and should of course also contain the path to the actual image and image.2jpg refers to the image, and path, of the image wanted after a member logs in.

    Obviously more 'elegant' ways of doing this.
  5. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    @sstark: I've updated my code example above, I had double upped on the quotes.

    To your example:

    Code:
    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print '<img src="Images/signup_sidebar.jpg" >';
    } else { // user is not logged-in
    print '<img src="Images/signup_fit_profile.jpg" >';
    }
    ?>
  6. CrackBaby

    CrackBaby Member

    Joined:
    Aug 22, 2006
    Messages:
    154
    if in the template file


    {php}
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    echo '<img src="/path/image1.jpg" >';
    } else { // user is not logged-in
    echo '<img src="/path/image2.jpg" >';
    }
    {/php}

    but I have not been able to get it to work since the 3.2.3 upgrade I am trying to pull off.
  7. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    Thank you, skippybosco! With the changes to the quotes it works perfectly. Really appreciate the help.:)

  8. CrackBaby

    CrackBaby Member

    Joined:
    Aug 22, 2006
    Messages:
    154
    My next guess was you were forgetting the session_start();

    glad you got it working


    Code:
    {php}
    session_start(); 
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    
    echo '<div> Welcome $au[name_f] $au[name_l]</div>';
    
    } else { // user is not logged-in
    
    echo '<div>Please Login</div>';
    
    } 
    {/php}
  9. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    I have another one for you all. I'm trying to get an if else statement to work within a table to determine between two functions. Any ideas why this won't work? Obviously I'm a newbie to PHP but I am learning and really liking it. What do you all think? The following code does print the first function but is not differentiating when the statement doesn't = m.

    Code:
    if ($_SESSION['_amember_user']['gender']=m){
    printf("%01.2f", (66+(6.23*($_SESSION['_amember_user']['weight']))+(12.7*($_SESSION['_amember_user']['height']))-(6.8*($_SESSION['_amember_user']['age'])))); 
    } else { 
    printf("%01.2f", (655+(4.35*($_SESSION['_amember_user']['weight']))+(4.7*($_SESSION['_amember_user']['height']))-(4.7*($_SESSION['_amember_user']['age'])))); 
    }
    ?>" />
  10. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is correct if:
    PHP:
    if ($_SESSION['_amember_user']['gender']=='m'){
    again this will work only if you have additional field "gender" setup, field type set to SQL and value can be m
  11. sstark

    sstark New Member

    Joined:
    May 31, 2010
    Messages:
    28
    Thank you alexander that works great!

Share This Page