A bookmark script in PHP allows users to save their favorite web pages for later access. The script can be used to create a simple bookmarking system for a website, or as a feature in a more complex application. Some popular bookmarking websites include Pocket, Reddit, Instapaper, Pinterest, Evernote Web Clipper, Sign-up for a free account, Hatena, Pearltrees, Pinterest, Pinboard, and We Heart It. CSS galleries are also a good source for bookmarking websites such as Unmatched Style, These Bookmarks, and This Bookmark by Greek. Social bookmarking sites such as Digg, Diigo, and Scoop.it also provide users with the ability to store and share their favorite web content. Additionally, there are many defunct bookmarking websites such as BookmarkSync, CiteULike, Clipmarks, Connotea, Delicious, Faves, Furl, Gnolia, My Web, Oneview, Simpy, StumbleUpon, Trackle, Twine, and Xmarks.
Here is an example of a basic bookmark script that allows a user to add and view their bookmarks:
<?php
session_start();
// Connect to the database
$db = new mysqli('localhost', 'dbuser', 'dbpassword', 'dbname');
// Check if the form has been submitted
if (isset($_POST['submit'])) {
// Escape user input to prevent SQL injection
$url = $db->real_escape_string($_POST['url']);
$title = $db->real_escape_string($_POST['title']);
// Insert the new bookmark into the database
$query = "INSERT INTO bookmarks (user_id, url, title) VALUES ('$_SESSION[user_id]', '$url', '$title')";
$db->query($query);
}
// Get the bookmarks for the logged-in user
$query = "SELECT * FROM bookmarks WHERE user_id = '$_SESSION[user_id]'";
$result = $db->query($query);
// Display the bookmarks
while ($bookmark = $result->fetch_assoc()) {
echo '<a href="' . $bookmark['url'] . '">' . $bookmark['title'] . '</a><br>';
}
// Display the "add bookmark" form
echo '<form method="post" action="bookmarks.php">
<label for="url">URL:</label>
<input type="text" id="url" name="url">
<br>
<label for="title">Title:</label>
<input type="text" id="title" name="title">
<br>
<input type="submit" name="submit" value="Add Bookmark">
</form>';
This script allows a user to save a URL and title in a database, and then displays a list of all the URLs the user has saved, with each item linking to the saved URL. When user submit the form the script inserts the new bookmark with the user’s ID and the URL and title they entered.
As always you should take in account security concerns as well. For example, you should validate the URL to ensure that it’s a valid URL, and also validate the title to ensure that it doesn’t contain any malicious code. You should also hash the user_id and check for the correct one in the DB to prevent session hijacking, and you should validate the CSRF token to prevent CSRF attacks.
This is a simple example and you can improve it by adding more functionality such as editing and deleting bookmarks, displaying bookmarks from a certain category, or adding a search feature, etc.