Dynadot โ€” .com Registration $8.99

PHP Session Help

Spaceship Spaceship
Watch

noswad

Established Member
Impact
1
Helloooo

Im using this PHP session to display data when a user logs in.

e.g.

session_start();
echo $_SESSION[console];

Basically - Its displaying their favourite games console in text.

The session will either display 'Xbox 360', 'Playstation 3' or 'Nintendo Wii'.

Is it possible to display a picture of their favourite console?

For example: if [console] = 'Xbox 360' -> display ../images/xbox360.jpg

You get what I mean!

Thanks for reading :kickass:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Why not use cookies?

Because if you use sessions and they close theire window, they have to reassign what favorite console they have.

edit:
Code:
<?php
if(isset($_POST['choose_console'])) {
if($selection == "1") { 
$_SESSION['console_1'] = $console_1;
session_register("console_1");
}
}

if(isset($_SESSION['console_1'])) { echo "<img src=picture.jpg>"; } 

?>

etc...

(didnt test the code )
 
Last edited:
0
•••
$favorite = $_SESSION[console];
$wii = "/home/user/public_html/wii.gif";
echo $favorite;
if ($favorite == "Wii") {
echo $wii;
}
 
0
•••
PHP:
session_start();

if ($_SESSION['console'] == 'Nintendo Wii') {
  echo 'wii stuff <img src="wiiimage.jpg" />';
} elseif ($_SESSION['console'] == 'Xbox 360') {
  echo '360 stuff <img src="360.jpg" />';
} elseif ($_SESSION['console'] == 'Playstation 3') {
  echo 'ps3 stuff <img src="ps3.jpg" />';
}

xlusive: your code has random variables that aren't used anywhere.
abdulmueid: yours wouldn't echo an image, just the path to it.
 
0
•••
xlusive - the user chose their favourite console when they registered. Thanks any way.

Hi abdulmueid

I can't get this code to work but thanks for trying.

David.
 
0
•••
There are other..probably even better ways to do it, but:
PHP:
<?php

session_start();

//I'm assuming you pull this info from the db
//on a login page, you could do the following

//if login successful
$_SESSION['console'] = $user_console_pref;

//Then wherever you want the image displayed

if (isset($_SESSION['console']))
{
    switch ($_SESSION['console'])
    {
        case 'Nintendo Wii':
             $console_stuff = 'wii stuff <img src="wiiimage.jpg" />';
             break;
        case 'Xbox 360':
             $console_stuff = '360 stuff <img src="360.jpg" />';
             break;
        case 'Playstation 3':
             $console_stuff = 'ps3 stuff <img src="ps3.jpg" />';
             break;
    }
    
    echo $console_stuff;
}

?>
 
0
•••
Thanks to both Dan Friedman and SecondVersion!

I was just about to kill myself!

Thanks again :kickass: :bingo:
 
0
•••
whoops... my bad. That was just a quick and dirty piece of code. Anyway, both your codes should work nicely :)
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back