NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Session Help

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-27-2006, 01:28 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



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
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
noswad is offline  
Old 05-27-2006, 01:52 PM   #2 (permalink)
Pro Coder & Designer
 
aween's Avatar
Join Date: Apr 2005
Location: Netherlands
Posts: 967
aween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really nice
 



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 )
__________________
aween web development
Last edited by aween; 05-27-2006 at 01:59 PM.
aween is offline  
Old 05-27-2006, 01:54 PM   #3 (permalink)
Account Closed
 
abdulmueid's Avatar
Join Date: Jun 2005
Location: Mozambique
Posts: 607
abdulmueid has a spectacular aura aboutabdulmueid has a spectacular aura about
 



$favorite = $_SESSION[console];
$wii = "/home/user/public_html/wii.gif";
echo $favorite;
if ($favorite == "Wii") {
echo $wii;
}
abdulmueid is offline  
Old 05-27-2006, 02:26 PM   #4 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
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') {
????: NamePros.com http://www.namepros.com/programming/201705-php-session-help.html
  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.
Dan is offline  
Old 05-27-2006, 02:30 PM THREAD STARTER               #5 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



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.
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
noswad is offline  
Old 05-27-2006, 02:37 PM   #6 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
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':
????: NamePros.com http://www.namepros.com/showthread.php?t=201705
             
$console_stuff '360 stuff <img src="360.jpg" />';
             break;
        case 
'Playstation 3':
             
$console_stuff 'ps3 stuff <img src="ps3.jpg" />';
             break;
    }
    
    echo 
$console_stuff;
}

?>
Eric is offline  
Old 05-27-2006, 03:17 PM THREAD STARTER               #7 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



Thanks to both Dan Friedman and SecondVersion!

I was just about to kill myself!

Thanks again
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
noswad is offline  
Old 05-27-2006, 03:54 PM   #8 (permalink)
Account Closed
 
abdulmueid's Avatar
Join Date: Jun 2005
Location: Mozambique
Posts: 607
abdulmueid has a spectacular aura aboutabdulmueid has a spectacular aura about
 



whoops... my bad. That was just a quick and dirty piece of code. Anyway, both your codes should work nicely
abdulmueid is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:14 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger