View Full Version : session accepting/using/storing

04-03-2004, 08:02 AM
hi everone,
eer...i really don't really know how to put this but here goes anyway...i am not good at all with sessions. not totally don't know about it but just somewhere there only..now, i have a page that needs to use sessions after the user log's in. now in that page, there are 30 images that needs to be uploaded. each has different names so it's not possible to loop it..right?ok now the prob is...how do i upload 30 pictures and also identify those 30 images that it belongs to the person that whoever signs-in?get what i mean? ok here is an example:

now lets say u have signed up in my webpage and have an account. nw u log in and u wanna upload ur 30 images. so how do i identify those 30 images belongs to you?and not other users when it goes into the database??like let's say me(mivec)once uploaded the images..how do i identify those 30 images belongs to me so it goes in as sets of 30's into the database?

that means i would be needing sessions to identify my nick(as i am using it as a unique value) so that i can insert to the database and identify my set of 30 images.and i dunno how to do this. can any of u experts help me pls?i am going nutz thinking about this as i am no good in sessions. pls help as i am desperately in need of it. thanking you all in advance.

04-03-2004, 08:36 AM
i don't udestand he problem.

When you upload,you'll have a form with 30 filefields. You can name these fields whatever you want. So you could give tham all the same name + a sequencenumber like raf1, raf2, raf3 etc

This way, you can process then in a loop

foreach($_POST as $var=>$value){
if ((substr($var, 0, 3)=='raf') and (strlen($value)>=1)){
your code

and to build them, you can just use a loop as well.


for ($i=1;$1<=30;$i++){
echo '...name="'. $nick . $i .'" ...

The nickname can then be selected from the db or so an stored inside a sessionvar like

// at the top of your page
... // other code including nick-selection

Note: using the nick as the unique identificationcriteria is probably not the best way to go. Don't you have a user-table or so with a primary key?

05-26-2004, 06:24 AM
thanks raf for the reply and sorry for this tremendously late reply...errmm.....i dun really understand what u were trying to tell me but u said this:

// at the top of your page
... // other code including nick-selection

errmm...if i am not mistaken..this part goes to the page that u are inputing ur username and password right?ok....so now, how do i keep my username that i have typed, check it with the db and then set the username into a session variable so that i can use this session variable to insert the username to the DB next time?

i hope u get what i mean raf?:)...or anyone else has a suggestion?

05-26-2004, 09:57 AM
These to lines are needed to store the nickname into the sessionvariable. If you place these in the file that your formposts to, then i'd look like

... // other code including nick-selection

If you want to retrieve the value on other pages, then you need

... // other code including nick-selection
$nick = $_SESSION['nick'];

For instance, to insert it to the db

... // other code
$sql="INSERT INTO table (var1, var2, nickname) values (1, 'test', '" . $_SESSION['nick'] . "')");

05-26-2004, 11:01 AM
in otherwords , whenever/however your user logs in you at that time set a session variable with at least the username (I prefer to work with the user_id)

then in any page that requires some knowledge of the user (or requires them to be logged in)


now you have $_SESSION['nick'] etc to play with as shown by Raf above.

For storing the images I like to either prefix the image name with an identifer or give the user thier own image directory , e.g. for an identifier..

$_FILES['fieldname']['tpm_name'] ,

so user `jimbo` 's image called tree.jpg is now stored as /img/upload/jimbo_tree.jpg etc

that , or copy to /img/upload/'.$_SESSION['username'].'/'.$_FILES['fieldname']['name']


etc , whether and how you log info about these images in the DB is another matter, I like this system as you dont need to rely on the DB for getting information about the images since thier location is logical.

06-01-2004, 04:45 AM
oh...thank you guys...i will try to see if i can put it into my code...thanks once again. :thumbsup:

by the way, u see,when i upload these images, i wanna store the picture number to it as it is uploaded one by one.

lets say, i have uploaded this image: mivec_tree.jpg and it's in the path img/userpics/mivec_tree.jpg. so in the database, there will be another field pic_Num to store the number of the picture once it is uploaded. the thing is, how can i check it from the database where the user has stopped?what i mean is that lets say if the user uploaded 5 pictures today.so the pic_num goes up to 5 right?and then the next day, he uploads another 10 pics. so how can i detect it that the first picture that he uploads on the next day starts at 6?also, how can i limit the user from uploading pics not more than 30?

i hope u guys can understand me..thanks in advance. :)