...

View Full Version : Checking sha1 with get in array



matak
07-17-2007, 04:27 AM
I have problem with this 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 :confused: Help

NancyJ
07-17-2007, 09:10 AM
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.

matak
07-17-2007, 04:27 PM
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].



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum