Jump to content

Likes using sessions ...


FarrisFahad
Go to solution Solved by 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
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.

Link to comment
Share on other sites

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.

Link to comment
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.

 

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.