 |
Results from the most recent live auction are here.
21 members in the live chat room. Join Chat!
| |
05-27-2006, 01:28 PM
|
· #1 | | NamePros Regular Location: Leeds, UK Join Date: Aug 2005
Posts: 260
NP$: 70.00 ( Donate)
| PHP Session Help 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 
__________________ C905 - Sony Ericsson mobile phone with an 8 megapixel camera!
|
| |
05-27-2006, 01:52 PM
|
· #2 | | Pro Coder & Designer Name: Karim Location: Netherlands Join Date: Apr 2005
Posts: 962
NP$: 62.00 ( Donate)
| 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 by xlusive : 05-27-2006 at 01:59 PM.
|
| |
05-27-2006, 01:54 PM
|
· #3 | | NamePros Regular Name: Abdul Mueid Location: Mozambique Join Date: Jun 2005 | $favorite = $_SESSION[console];
$wii = "/home/user/public_html/wii.gif";
echo $favorite;
if ($favorite == "Wii") {
echo $wii;
} |
| |
05-27-2006, 02:26 PM
|
· #4 | | Buy my domains. Name: Dan Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 ( Donate)
| PHP Code: 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. |
| |
05-27-2006, 02:30 PM
|
· #5 | | NamePros Regular Location: Leeds, UK Join Date: Aug 2005
Posts: 260
NP$: 70.00 ( Donate)
| 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.
__________________ C905 - Sony Ericsson mobile phone with an 8 megapixel camera!
|
| |
05-27-2006, 02:37 PM
|
· #6 | | while ($awake){ code(); } Name: Eric Location: Kentucky Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 ( Donate)
| There are other..probably even better ways to do it, but: PHP Code: <?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;
}
?> |
| |
05-27-2006, 03:17 PM
|
· #7 | | NamePros Regular Location: Leeds, UK Join Date: Aug 2005
Posts: 260
NP$: 70.00 ( Donate)
| Thanks to both Dan Friedman and SecondVersion!
I was just about to kill myself!
Thanks again 
__________________ C905 - Sony Ericsson mobile phone with an 8 megapixel camera!
|
| |
05-27-2006, 03:54 PM
|
· #8 | | NamePros Regular Name: Abdul Mueid Location: Mozambique Join Date: Jun 2005 | whoops... my bad. That was just a quick and dirty piece of code. Anyway, both your codes should work nicely  |
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |