PHP Session Help

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
$favorite = $_SESSION[console];
$wii = "/home/user/public_html/wii.gif";
echo $favorite;
if ($favorite == "Wii") {
echo $wii;
}
 
0
Close
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
Close
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
Close
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
Close
Thanks to both Dan Friedman and SecondVersion!

I was just about to kill myself!

Thanks again :kickass: :bingo:
 
0
Close
whoops... my bad. That was just a quick and dirty piece of code. Anyway, both your codes should work nicely :)
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back