deluxor Posted September 27, 2012 Share Posted September 27, 2012 Hello people could you please explain me or make me look out what is wrong with this code? Basically I have a table with some domains, after a query I split them by "," then I want to check if the referer is one of those domains in the DB, if true nothing happens, if not they got redirected to a new page, I can't figure out what is wrong, can someone please help me? Thanks in advance! $streama= preg_replace("/[^a-zA-Z0-9\s]/", "", $_GET['ch']); mysql_select_db($database_ovcast, $ovcast); $query_Recordset1 = "SELECT nome, visitas, ban, password, dominio FROM CANAIS WHERE nome = '".$streama."'"; $Recordset1 = mysql_query($query_Recordset1, $ovcast) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); if ($row_Recordset1['dominio'] != "n/a"){ $parts = split (",",$row_Recordset1['dominio']); $urlInfo = parse_url($_SERVER['HTTP_REFERER']); $domain = $urlInfo['host']; $conta = count($parts); for ($i = 0; $i < $conta; $i++) { //echo $parts[$i]."\n"; if ($parts[$i] <> $domain) { header("Location: http://#"); //exit; } } } Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/ Share on other sites More sharing options...
trq Posted September 27, 2012 Share Posted September 27, 2012 Why are you storing multiple domains within a single column in the first place? If you store your data properly you will be able to query the database for the data you actually need instead of having php do all the work. Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/#findComment-1381449 Share on other sites More sharing options...
deluxor Posted September 27, 2012 Author Share Posted September 27, 2012 Thank you very much for your fast reply, so what I understood was, distribute the domains trought more columns and then compare them directly? Deluxor Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/#findComment-1381452 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Share Posted September 28, 2012 What he is saying is, rather than comparing them through ',' try using a while loop to grab all the domains from the database, and loop them through a table row or a div. Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/#findComment-1381457 Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Share Posted September 28, 2012 An example loop that im using on a cms im developing at the moment would be: <?php echo "<ul>"; $mainNav = select("*", "pages"); $Nav = $mainNav; while($fetch = mysql_fetch_assoc($Nav)){ $path = $GLOBALS["siteUrl"]."/template/".$fetch["pageLink"]; if($fetch["active"] == 1 && $fetch["pageType"] == 1){ echo "<li><a href='".$path."'>".$fetch["name"]."</a></li>"; } if($fetch["active"] == 1 && $fetch["pageType"] == 2){ echo "<li><a href='".$GLOBALS["siteUrl"]."/template/page.php?name=".$fetch["name"]."'>".$fetch["name"]."</a></li>"; } if($fetch["active"] == 1 && $fetch["pageType"] == 4){ echo "<li><a href='".$path."'>".$fetch["name"]."</a></li>"; } } echo "</ul>"; ?> Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/#findComment-1381458 Share on other sites More sharing options...
Christian F. Posted September 28, 2012 Share Posted September 28, 2012 Not quite, I'm afraid. What he's saying is the normalize the database properly, or in other words: Store the domains in a table of their own, and use a foreign key relation. These videos explain the concept rather nicely, and I recommend viewing them and researching the 3rd normal form until you understand the concept: Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/#findComment-1381465 Share on other sites More sharing options...
deluxor Posted September 28, 2012 Author Share Posted September 28, 2012 Ok I got it, thank you very much for all your replys! I just remaked the DB. Link to comment https://forums.phpfreaks.com/topic/268864-loop-issue/#findComment-1381467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.