TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-17-2008, 01:48 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Smile multi users uploading an image to a table

hi, im creating a script that will allow multiple users upload multiple images and will view the images only that they uploaded.

this is the table structure i used

Code:
id
username
title
image
as you can see i added the username column which will be grabbed from the cookie. now my question is , is this the right way of doing this? if i had 100 people login to this script and each person uploaded 10 images to this table and their images were displayed neatly to them in a table. how else can this be done?
thanks

ps: this is what the table might have looked like after having 3 people upload 5 images each.

Code:
id: 1
username: bob
title: cartoon
image: someimage.png(encoded)

id: 2
username: bob
title: balloons
image: someimage.png(encoded)

id: 3
username: bob
title: ocean
image: someimage.png(encoded)

id: 4
username: bob
title: pc
image: someimage.png(encoded)

etc.....
then when i want to display each users images i would run a query like this

Code:
$username = $_COOKIE['username'];
$sql = mysql_query("select * from tbl_logos where username = '$username'");

while($row = mysql_fetch_assoc($sql)) {

echo data.....

}
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 06-18-2008, 12:36 AM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by sarmenhb View Post
hi, im creating a script that will allow multiple users upload multiple images and will view the images only that they uploaded.

this is the table structure i used

Code:
id
username
title
image
as you can see i added the username column which will be grabbed from the cookie. now my question is , is this the right way of doing this? if i had 100 people login to this script and each person uploaded 10 images to this table and their images were displayed neatly to them in a table. how else can this be done?
thanks

ps: this is what the table might have looked like after having 3 people upload 5 images each.

Code:
id: 1
username: bob
title: cartoon
image: someimage.png(encoded)

id: 2
username: bob
title: balloons
image: someimage.png(encoded)

id: 3
username: bob
title: ocean
image: someimage.png(encoded)

id: 4
username: bob
title: pc
image: someimage.png(encoded)

etc.....
then when i want to display each users images i would run a query like this

Code:
$username = $_COOKIE['username'];
$sql = mysql_query("select * from tbl_logos where username = '$username'");

while($row = mysql_fetch_assoc($sql)) {

echo data.....

}

Code:
$sql = mysql_query("select * from tbl_logos where username = '$username'");
Is a potential sql injection threat. Do this:
Code:
$sql = mysql_query("select * from tbl_logos where username = '".mysql_real_escape_string($username)."'");
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 06-18-2008, 03:40 AM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

thank you for that, i should go back and change all other coding like that to be on the safe side.

-----

so its ok to have users information displayed to them based on their username like i've done it?

what i was also thinking was if i have a file called img.php and this file would display the user his image based on the id that was passed to another page meaning that

img.php?id=$row['id']

to have the img.php check to see if user who is asking to see the file actually does have the image and doesnt try to hack to see another persons image.

so he cant go and type img.php?id=5 or id=4 in the url

get what im saying?

i'll also use url rewrite once i understand the regex part of it :p
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 06-18-2008, 11:33 AM   #4 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

Well the info in the Cookie could be changed giving other users access to pictures they shouldent. So i would go about to use user ID:s and SESSION variables to get them. in other words, save the USER id into a SESSION at login and then use it when displaying the users pictures.
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 06-18-2008, 03:30 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Don't store files in the database, it will be a really bad thing if you get even remotely high traffic. Let the filesystem handle files and the database handle data. Store the files in a folder below the webroot and pull them up only if they have the proper credentials.

Also, don't track users by username. It is best to use a unique ID assigned to each user (primary keys+auto_increment is a good way to do this). That way you can change any user credential and things wont go different.

Lastly, verify your data. Besides being open to SQL injection, anything the user places on the cookie will be accepted. You will want to verify that the user in question is actually that user before displaying anything.
__________________

Village Idiot is offline  
Reply With Quote
Old 06-19-2008, 10:31 PM   #6 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Quote:
Originally Posted by EyeDentify View Post
Well the info in the Cookie could be changed giving other users access to pictures they shouldent. So i would go about to use user ID:s and SESSION variables to get them. in other words, save the USER id into a SESSION at login and then use it when displaying the users pictures.
Normally info in session data or even cookie data (session data can be cookie data if not using the transid option in session) include a login hash of some sort which is used to identify a login, and the login check would check if the id in the session or cookie variable matches the one with the login hash and if it fails it would halt script execution.

Or atleast thats what real time application does =)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 06-29-2008, 04:10 AM   #7 (permalink)
The Visitor
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
pradeepsomani is on a distinguished road
Default

Quote:
Originally Posted by sarmenhb View Post
hi, im creating a script that will allow multiple users upload multiple images and will view the images only that they uploaded.

this is the table structure i used

Code:
id
username
title
image
as you can see i added the username column which will be grabbed from the cookie. now my question is , is this the right way of doing this? if i had 100 people login to this script and each person uploaded 10 images to this table and their images were displayed neatly to them in a table. how else can this be done?
thanks

ps: this is what the table might have looked like after having 3 people upload 5 images each.

Code:
id: 1
username: bob
title: cartoon
image: someimage.png(encoded)

id: 2
username: bob
title: balloons
image: someimage.png(encoded)

id: 3
username: bob
title: ocean
image: someimage.png(encoded)

id: 4
username: bob
title: pc
image: someimage.png(encoded)

etc.....
then when i want to display each users images i would run a query like this

Code:
$username = $_COOKIE['username'];
$sql = mysql_query("select * from tbl_logos where username = '$username'");

while($row = mysql_fetch_assoc($sql)) {

echo data.....

}
Please Check the attached database design.

MySQL code

Create table tbluser (
userid Int NOT NULL AUTO_INCREMENT,
username Varchar(20),
userpassword Varchar(20),
userdeleteflag Bool,
Primary Key (userid)) ENGINE = InnoDB;

Create table tblimage (
imageid Int NOT NULL AUTO_INCREMENT,
userid Int NOT NULL,
imagefile Varchar(50),
imagetitle Varchar(50),
imagedeleteflag Bool,
Primary Key (imageid)) ENGINE = InnoDB;


Alter table tblimage add Foreign Key (userid) references tbluser (userid) on delete restrict on update restrict;
Attached Thumbnails
multi-users-uploading-image-table-db.jpg  
pradeepsomani is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:21 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design