asdrubal
asdrubal

Reputation:

Home page with favourite links

I'm building a homepage (intranet for small company) that would essentially have about 50 links on it stacked in 5 columns. What I want to do is to make 6th column that would allow anyone to type about 10 of his private links. This would have to be done without having to login, as there is not gonne be any login form. Links should be visible after restaring browser, but could dissapear after lets say deleting temporary internet files or cookies.

Could someone point me in the right direction here? I think I may have to use forms to do it, but don't really know how to start.

Upvotes: 0

Views: 77

Answers (2)

PeeHaa
PeeHaa

Reputation: 72672

I think you have two options:

  1. local storage
  2. cookies

The first option requires a modern browser (since it is a HTML5 feature).

The second option requires some backend scripting (PHP / ASP) to set the cookie.

I think the second option would the perfered because you have the biggest chance to make it cross-browser.

The second option would look something like (untested, but you get the idea):

The code of the 6th column

<?php
    if (isset($_COOKIE['custom_url'])) {
        $urls = json_decode($_COOKIE['custom_url']);

        foreach($urls as $url) {
            echo '<a href="'.$url.'">'.$url.'</a>';
        }
    }
?>

The HTML of the form

<form action="/save.php" methos="post">
  <input type="text" name="url">
  <input type="submit" value="Save">
</form>

The PHP

<?php

if ($_POST['url']) {
    $urls = array();
    if (isset($_COOKIE['custom_url'])) {
        $urls = json_decode($_COOKIE['custom_url']);
    }
    $urls[] = $_POST['url'];

    setcookie('custom_url', json_encode($urls));
}

Upvotes: 1

Aaron Lee
Aaron Lee

Reputation: 1156

The best way to do it from my knowledge, would be to create some kind of session via a cookie etc which would store the necessary information on there machine, therefore, once someone has deleted their personal temporary internet files it would disappear. This can achieved via php.

http://www.tizag.com/phpT/phpsessions.php

That would probably be your best starting place.

Upvotes: 0

Related Questions