This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Login System Avatar
#1
Question 

Hello there,

I have a login system on my site and I want my users to upload avatars they want so these avatars can be displayed on the commenting system. If there are no logged in users then show default image.

Is that snippet beyond your service?
Reply
#2

Hi,

Does your site already have the ability for users to upload their avatars? If so then it wouldn't be difficult to integrate that with Commentics and I could provide help with that. If your site doesn't have that ability and you're asking for me to build it, either for your site or for Commentics itself, then yes it's beyond the support of the project.

Have you completed the interview?
Reply
#3

Fortunately, I have the ability to upload avatars.

I have the following code but when I log in my avatar is on the every comment then...

I know that there is should be another logic. I'm still thinking exactly what kind of logic...

Here's my code

PHP Code:
<?php 
$stmt
= $db->prepare("SELECT * FROM users WHERE user_id = :user_id");
// bind the parameters
$stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_STR);
// execute the prepared statement
$stmt->execute();

$row = $stmt->rowCount();
if (
$row != NULL)
{
while (
$row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if (
$row['user_id'])
{
$old_picture = $row['picture'];
$cmtx_box .= '<img src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" />';
}
}
}
else
{
$cmtx_box .= "<img src='http://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . ".png?s=71" . $gravatar_parameter . "' alt='Gravatar' title='Gravatar'/>";
}
Reply
#4

I think you'll need to search your users table based on the email address. For example:

PHP Code:
<?php 
$stmt
= $db->prepare("SELECT * FROM users WHERE email = :email");

// bind the parameters
$stmt->bindParam(':email', $email, PDO::PARAM_STR);

Have you completed the interview?
Reply
#5

Ideally you should add another column to the comments table in the Commentics database called something like user_id. When someone posts a comment the id of the logged in user would save to that column.

Then in the code, when generating each comment, you get the user_id from the comments table and then you can use your original code:

PHP Code:
<?php 
$stmt
= $db->prepare("SELECT * FROM users WHERE user_id = :user_id");

Have you completed the interview?
Reply
#6

Steven, thank you for your wise thoughts.

Appreciate all your hard work.
Reply
#7

Dear Steven,

As yo can see from the attached images I have a broken links to user avatars and my database field is empty (avatar_108.png belongs to another user).

I have the following php code:

PHP Code:
<?php 
$stmt
= $db->prepare("SELECT picture FROM users WHERE email = :email");
// bind the parameters
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
// execute the prepared statement
$stmt->execute();

$rowCount = $stmt->rowCount();
if (
$rowCount > 0)
{
while (
$row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$old_picture = $row['picture'];
$cmtx_box .= '<img src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" />';
}
}
else
{
$cmtx_box .= "<img src='http://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . ".png?s=71" . $gravatar_parameter . "' alt='Gravatar' title='Gravatar'/>";
}

So anyway my script leads to user defined picture but not to gravatar image. Why?

Where am I wrong?

Cheers!


Attached Files Thumbnail(s)
       
Reply
#8

Have you viewed the source of the page to check what the Gravatar URL looks like?

Have you completed the interview?
Reply
#9

How the source of gravatar can help me to solve that, Steve?

Every gravatar URL looks different because of md5 as far as I know.
Reply
#10

For it to show a broken image and not a proper Gravatar suggests to me that the URL is not in the right format (see below example of correct way). So viewing the source of the URL will help you to determine that the URL looks like it's meant to. By this I mean for example that there is no error message where the $email variable is hashed and where the $gravatar_parameter variable is added. If it looks okay then try copying the URL from the source and pasting it into the address bar of a new tab to see if the resulting image is still broken and whether you can notice anything wrong.

But if the only reason you're using the Gravatar URL is to show the default image then it may be better and faster to serve it locally. So maybe just download the default image and include it from your site similar to how you're doing it with the avatars.

http://www.gravatar.com/avatar/4adcca49b...0&r=g&d=mm

Have you completed the interview?
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by drwx
29-Jun-2023, 09:34 AM
Last Post by Carluti
09-Jan-2016, 04:26 PM

Forum Jump:


Users browsing this thread: 5 Guest(s)