Jump to content

Loop Issue


deluxor

Recommended Posts

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? sad.gif

 

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.