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.
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?
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.
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.
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.
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.
@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.
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!!!!
I use phpThumb for such things.
This topic is now closed. New replies are no longer allowed.