Jump to content

Likes using sessions ...


FarrisFahad

Recommended Posts

Hello there members of PHP Freaks,

 

I am having a problem in PHP, I want to make the user like a picture and after he likes it the like button goes away.

 

I tried this,

<?php if(!isset($_SESSION["punch_id_" . $fetch["punch_id"]])){<a href="Like.php">Like</a>} ?>

and I also have tried,

<?php if($_SESSION["punch_id_" . $fetch["punch_id"]] == "punch_id_" . $fetch["punch_id"]){<a href="Like.php">Like</a>} ?>

So my question is ...

How can I make the like button disappear after the user have clicked it?

useing $_SESSION[].

 

 

Link to comment
https://forums.phpfreaks.com/topic/278447-likes-using-sessions/
Share on other sites

Hi Fahad, 

 

I just came across your snippet question and I think I could use a similar solution. Ofcourse I am trying to find a solution to a login issue. Ithink the $fetch command in your php is an ajax implimentation. Can you please quickly explain how this line of code works. Thats all I want to know. Thanks.

Hello Jessica, thanks for the reply. I thought it was ajax cos i thought .$fetch was a command. I am absolutely unfamiliar with ajax but that came into my head and so i wrote that. 

 

However i was interested in that line of code because it seems to be checking for session authentication before a button is clicked. That means the code following the if would be executed if ,in this case the session was valid. This was exactly what i was wanting to achieve in a 'user login system" that i am trying to create. I have asked this in another thread started by me named / called " Another login twister". 

 

I hope you can help. Thanks loads.

Hi Fahad, 

 

I just came across your snippet question and I think I could use a similar solution. Ofcourse I am trying to find a solution to a login issue. Ithink the $fetch command in your php is an ajax implimentation. Can you please quickly explain how this line of code works. Thats all I want to know. Thanks.

 

Hi, here is how I did it,

 

the below is the like button:

<?php if(!isset($_SESSION["punch_id_" . $fetch["punch_id"]])){ ?><a href="Like.php">Like</a><?php }else{ echo NULL; } ?>

And here is the like.php file:

<?php 

require_once("connection.php");

$id = $_GET["id"];

mysql_query("UPDATE table SET likes = likes + 1 WHERE id = {$id}");

$_SESSION["punch_id_" . $punch_id] = "punch_id_" . $punch_id;

header("Location: ../PicturePunches.php");
exit;

?>

I hope that helps :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.