getting images from folder using session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

getting images from folder using session

Post by pleigh »

i created a folder for images. i want my program to be like this, if the user entered his username and password, his picture will be displayed to the index page.

my question is, what syntax should i use to access or get the jpg file to be displayed in the index page

tnx

pleigh :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'd need to know what filename to load, this should be stored in the database in the user's settings (hidden from their direct control).

It's then a matter of knowing if the file is there and then writing out the image tag into the html stream.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

what syntax are you applying for naming images.

I suggest you name them on the username they correspond to.

then afterwards you can put img src in page using username var.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

feyd wrote:you'd need to know what filename to load, this should be stored in the database in the user's settings (hidden from their direct control).

It's then a matter of knowing if the file is there and then writing out the image tag into the html stream.

im going to have to agree with fyed its the best solution sorry n00b Saibot even though your solution will work, but putting the information in the database is better
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

...

Post by s.dot »

Assuming your information is in a database, I would do this,

Create your login box linking to a script to validate login / in this example "login.php"

Code: Select all

<? //login box ?> 
<form action="login.php" method="post">
<input type="hidden" name="action" value="login">

username<BR>
<input type="text" name="username" size="20"><BR><BR>
password<BR>
<input type="password" name="password" size="20"><BR>
<input type="submit" value="Login">
</form>
Then, this would be your login.php page

Code: Select all

<?

if($action == "login")&#123;

// perform code here that validates user's existence
// If user exists, go to page where you want picture to appear
$username = $_POST&#1111;'username'];
header("Location: index.php?username=$username"); &#125;
?>
Then to display their picture on the page where you want it to appear

Code: Select all

<? $sql = "SELECT picturename FROM database_table WHERE username = '$username'";
$result = mysql_query($sql); ?>
<img src="/path/to/your/pictures/<? echo $result; ?>">
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

PrObLeM wrote: sorry n00b Saibot even though your solution will work, but putting the information in the database is better
:lol: My solution doesn't involve overhead on a db connection. it would be much faster my way. but anyway, I think atleast he is much better informed now to take decision on his own :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

needing a database connection to find information all depends on what you have cached off in say.. a filesystem session... if the system already incorporates a query against the table holding the data, it doesn't add more than a few milliseconds (at most). But let's face it, php, along with pretty much all the other interpretted scripting language, isn't the fastest kid on the block...
Post Reply