Search code examples
phpgethref

Can I set a PHP session from a link title when I clicked it?


I would like to store in a session the text which clicked.

$sql = mysqli_query($conn, "SELECT * FROM movies WHERE id = '".$_GET['id']."'");
                                while ($movie = mysqli_fetch_array($sql))
                                {
                                    $mdirector = $movie['director'];
                                }
$directors = explode(", ", $mdirector);
                            foreach ($directors as &$d) {
                                $sd = sanitize($d);
                                $d = "<a href=\"/movies/director/$sd-movies\" id='mov' title='$d movies' itemprop='name'>$d</a>";
                            }

If a director's name has special characters like: Per-Olav Sørensen

The sanitize function change all special character to normal, so in the browser like this:

movies/director/per-olav-sorensen-movies

The sanitize function:

    function sanitize($string, $force_lowercase = true, $anal = false) {
    $strip = array("„","”","~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
                   "}", "\\", "|", ";", ":", "\"", ".", "'", "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;",
                   "—", "–", ",", "<", ".", ">", "/", "?");
    $clean = trim(str_replace($strip, "", strip_tags($string)));
    $clean = str_replace(array(" - ","À","Á","Â","Ã","Ä","Å","Ǻ","Ā","Ă","Ą","Ǎ","à","á","â","ã","å","ǻ","ā","ă","ą","ǎ","ª","ä","Ç","Ć","Ĉ","Ċ","Č","ç","ć","ĉ","ċ","č","Ð","Ď","Đ","ð","ď","đ","È","É","Ê","Ë","Ē","Ĕ","Ė","Ę","Ě","è","é","ê","ë","ē","ĕ","ė","ę","ě","Ĝ","Ğ","Ġ","Ģ","ĝ","ğ","ġ","ģ","Ĥ","Ħ","ĥ","ħ","Ì","Í","Î","Ï","Ĩ","Ī","Ĭ","Ǐ","Į","İ","ì","í","î","ï","ĩ","ī","ĭ","ǐ","į","ı","Ĵ","ĵ","Ķ","ķ","Ĺ","Ļ","Ľ","Ŀ","Ł","ĺ","ļ","ľ","ŀ","ł","Ñ","Ń","Ņ","Ň","ñ","ń","ņ","ň","ʼn","Ò","Ó","Ô","Õ","Ō","Ŏ","Ǒ","Ő","Ơ","Ø","Ǿ","Ö","ò","ó","ô","õ","ō","ŏ","ǒ","ő","ơ","ø","ǿ","º","ö","Þ","Ŕ","Ŗ","Ř","ŕ","ŗ","ř","Ś","Ŝ","Ş","Š","ś","ŝ","ş","ș","š","ſ","Ţ","Ť","Ŧ","ţ","ť","ŧ","Ù","Ú","Û","Ũ","Ū","Ŭ","Ů","Ű","Ų","Ư","Ǔ","Ǖ","Ǘ","Ǚ","Ǜ","Ü","ù","ú","û","ũ","ū","ŭ","ů","ű","ų","ư","ǔ","ǖ","ǘ","ǚ","ǜ","ü","Ý","Ÿ","Ŷ","ý","ÿ","ŷ","Ŵ","ŵ","Ź","Ż","Ž","ź","ż","ž","Æ","æ","Ǽ","ǽ","ß","IJ","ij","Œ","œ","ƒ",),
                         array("-","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","c","c","c","c","c","c","c","c","c","c","d","d","d","d","d","d","e","e","e","e","e","e","e","e","e","e","e","e","e","e","e","e","e","e","g","g","g","g","g","g","g","g","h","h","h","h","i","i","i","i","i","i","i","i","i","i","i","i","i","i","i","i","i","i","i","i","j","j","k","k","l","l","l","l","l","l","l","l","l","l","n","n","n","n","n","n","n","n","n","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","p","r","r","r","r","r","r","s","s","s","s","s","s","s","s","s","s","t","t","t","t","t","t","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","u","y","y","y","y","y","y","w","w","z","z","z","z","z","z","ae","ae","ae","ae","ss","ij","ij","oe","oe","f"), $clean);
    $clean = preg_replace('/\s+/', "-", $clean);
    $clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ;
    return ($force_lowercase) ?
        (function_exists('mb_strtolower')) ?
            mb_strtolower($clean, 'UTF-8') :
            strtolower($clean) :
        $clean;
        if(preg_match('/[^\\p{Common}\\p{Latin}]/u', $clean) == 1)
            {$clean = "";}
}

And in the linked page if I read the $_GET[director] I get "per-olav-sorensen-movies" and I can't use it with the database.

How can I store the original text, or decode the sanitized?


Solution

  • i think you must make table normalization. you can make a directors table an make relationship to movies table, And save sanitize name of director to a field.

    Example:

    directors table:

    id
    name
    slug // field to save sanitize director name
    

    movie table:

    id
    director_id
    name
    

    so you can make query to select all movies has relationship to x directors.

    select movies.*, directors.name from movies inner join directors on directors.id = movies.director_id where directors.slug = '$_GET[director]'