jemz — 2012-11-13T13:27:36-05:00 — #1
Hi, I need some help to you, i want to know how can i do this,when after the user login.I want that to put picture besides his name just like the same in the facebook after we login..can you help me please how can i do this.
Welcome <img> jemz.
Thank you in advance.
sheegoth — 2012-11-13T18:57:23-05:00 — #2
Where exactly do you want this image to be displayed?
Facebook displays the user's image beside their name in the top-most bar (next to navigation).
Are you trying to do the same?
jemz — 2012-11-14T01:56:33-05:00 — #3
Yes, just like that.can you help me please i have no idea on this.I hope you can help me.thank you in advance.
spikez — 2012-11-14T04:45:00-05:00 — #4
ok so you need a few things in place before this will happen.
1/ give the user an upload form so they can upload their image.
2/ resize the image to fit with your dimensions
3/ store the filename in the database table along with the other user information.
4/ query the database to get all the user info including the image name.
5/ add the image tag to the users profile and display the image that is stored on your server.
cups — 2012-11-14T04:55:55-05:00 — #5
Make sure every login is unique, and to make is easier make sure each login only contains characters which are allowed in a valid file name.
I know, like jemz or Cups
then when they upload their image, name it after their user name.
"Hi there jemz, here is your picture "
if( !isset($_SESSION['username']) )
// send away to login
$username = $_SESSION['username'];
// do some kind of data cleansing here
// disallowing directory traversal attacks
// being aware a clever user could add dots and slashes
// to their original user name
echo "Hi there $username,";
// make sure the file exists
if( file_exists('/user-images/' . $username. '.jpg'))
echo ' here is your picture <img src="/user-images/' . $username . 'jpg" />';
This is just an incredibly simplified example of how you could go about things ie username === image name plus .jpg, but you have to be very very careful to defend against simple attacks - as my comments hopefully show, I have no idea how clean or "tamper-able" the data getting to your SESSION is.
tentim — 2012-11-14T05:45:04-05:00 — #6
Let users upload their pics, save the path to the pics in db column, say, image_column
You login query should do something like this:
$sel = select image_column from users_table where username='$user_name' limit 1
$SESSION['pathto_image'] = $row['image_column']
Then in the member area:
$path_to_image = $SESSION['pathto_image']
echo "<img src='$path_to_image'>" anywhere you want the image to appear.
Note these are just code ideas, not actual code.
jemz — 2012-11-14T07:39:23-05:00 — #7
@spikeZ,@Cups,@tentim...Thank you for giving this idea.okay i will try to make a simple upload form...but i have question what if the uploaded picture is 500x400 and then how can i resize this to display it to 23px or just the same the size in the facebook...Thank you in advance.
spikez — 2012-11-14T07:57:53-05:00 — #8
Have a look for a simple upload and resize script jemz. There are plenty around and they will upload the picture to your server and then resize it to the width/height you tell them.
Whatever you do DO NOT upload a 500px wide picture and then use the browser to squash it down to 23px!!!!
tentim — 2012-11-14T17:08:39-05:00 — #9
I use phpThumb for such things.