November 14, 2012
Show delete message URL based on username
Question by user1793122
I have an PHP + Jquery wall message that show all message from anybody. Now I want to set delete URL in every messages. But the rule, user can’t see delete url if the messages is not his own.
.childs {
opacity: 0;
color: #000;
margin-left: 10px;
float: right;
}
.childs:hover {
opacity: 1.0;
text-decoration: underline;
cursor: pointer;
}
.parents:hover > .childs {
opacity: 1.0;
}
—
This logged in as Greg
<section class="parents">
Greg : Today is holiday
<div class="childs"><a href="delete.php">Delete</a></div>
This logged in as Jeremy
<section class="parents">
Jeremy : Beautiful day
<div class="childs"><a href="delete.php">Delete</a></div>
I want the Delete link show based on username logged in. So if Jeremy mouse over Greg message, delete link will not show because it’s not his message and if Greg mouse over his own message, he can see the delete url link and can delete it.
So how can I set that ?
Thanks for helps.
Answer by Starx
This is a simple approach. Store the logged in information of session using $_SESSION
then compare this on your view class/code.
Like
<div class="childs">
<?php
if($_SESSION['logged_in_user'] == true) {
echo "<a href='delete.php'>Delete</a></div>";
}?></div>