Session keywords and dynamic image insertion

Discussion in 'PHP' started by BobC, Sep 26, 2010.

  1. #1
    Hi,

    I'm getting a little stuck with using session variables. I can start a session ok, and then use this to strip out hyphens for dynamic keyword and image insertion.

    I can happily echo $MainKeyWord anywhere with alternative text. However, when i try and do similar with calling up an image I can't get the alternative filename (here it's 'default') to work:

    I'm basically trying to do this - if there is a session keyword then use the stripped down version of that ($picword) as the filename, else use default.

    It works ok with the session keyword but never shows the default image.

    I think the problem might be to do with not clearing the session variable properly, although maybe the snippet I've written is not suitable?

    Any ideas would be greatly appreciated,

    thanks, Bob
     
    BobC, Sep 26, 2010 IP
  2. Media Signal

    Media Signal Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <img src="images/<?php if (!empty($_SESSION['KW'])) { echo $picword; } else { echo 'default'; } ?>.png" title="" alt="" />
    PHP:
    If it doesn't work, $_SESSION['KW'] is always set and holds some value - clear it and the default image should appear as expected.
     
    Media Signal, Sep 26, 2010 IP