Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts

    Checking sha1 with get in array

    I have problem with this code

    PHP Code:
    <div id="lijevo">

    <?php
    $linkovi 
    = array ("Varijable i php čćžđš" => "php/tutorijal1""Varijable 2 dio" => "php/tutorijal2");
    $paths array_values ($linkovi);
    echo 
    "<ul>";
    foreach (
    $linkovi as $title => $path){
    echo 
    "<li><a href=\"?sid=".sha1($path)."\">$title</a></li>";
    }
    echo 
    "</ul>";
    ?>

    </div>
    <div id="desno">
    <?php

    if (!isset($_GET['sid'])){
        include (
    "stranice/index/index.html");
    }
    elseif (
    $_GET['sid']) {
        
    checkSid ($_GET['sid'], $paths);
    }
    function 
    checkSid ($value$paths){

    foreach (
    $paths as $sid){

        if (
    sha1($sid) == $value):
        
            include (
    "stranice/".$sid.".html");
            
        elseif (
    sha1($sid) !== $value):
        
            include (
    "stranice/index/index.html");
            
        endif;
    }
    }
    ?>
    </div>
    When i click on the first link it includes the first file, and the Index file, and when i click on the second link it first includes the index file and then the first file. I just don't get it Help

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Your looping through your paths and checking each one against the sid you've got. If it doesnt match, you include the index.
    When you try the first link, the first value in the array matches your sid and so that file is included, the second link in the array doesnt match, so it includes the index.
    When you try the second link, the first value in the array is no match so it includes the index, the second value does match, so the page is included.

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    i solved the problem by creating a new sha1 array from paths. then by checking with in_array, and using array_search to look for the key matches in pathssid and paths array, then including it with same key like this

    paths[key].


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •