Function problem
| From: | Jan Hanèiè | Date: | Wed, 17 Jul 2002 18:10:59 +0000 |
| Subject: | Function problem | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-14808@lists.php.net to get a copy of this message | ||
Hi
I hawe the following script :
<?
include("glava.php");
///////// FUNKCIJE ///////////
/*
Funkcija ki preveri èe je URL prave oblike
*/
function je_url($url) {
if (ereg("^http://*", $url))
{
return TRUE;
}
else
{
return FALSE;
}
}
function preveri($vir, $vir_url) {
if ($vir || ( $vir && je_url($vir_url)) || (!$vir && !$vir_url))
{
return true;
}
else
{
return false;
}
}
/*
Funkcija ki najrpej preveri èe je s podatki vse vredu in jih ptoem doda v bazo
*/
function dodaj() {
if($_POST['naslov'] && $_POST['vsebina'] && $_POST['avtor'] && $_POST['datum'] && preveri($_POST['vir'], $_POST['vir_url']))
{
$naslov = strip_tags($_POST['naslov'], "<b><i><a><img><u><p><br>");
$vsebina = strip_tags($_POST['vsebina'], "<b><i><a><img><u>");
$avtor = strip_tags($_POST['avtor'], "<b><i><a><img><u>");
$datum = $_POST['datum'];
$vir = $_POST['vir'];
$vir_url = $_POST['vir_url'];
$query = "insert into novice_novice (novica_naslov, novica_vsebina, novica_avtor, novica_datum, novica_vir, novica_vir_url)
values('$naslov', '$vsebina', '$avtor', '$datum', '$vir', '$vir_url')";
MYSQL_QUERY($query) or
die (MYSQL_ERROR());
echo "Novica vneena !";
echo "<br>Èez 3 sekunde boste preusmerjeni na glavni meni !";
?>
<script>
window.setTimeout("document.location.href='./main.php'", 3000);
</script>
<?
}
else
{
echo "Nisi vpisal vseh podatkov! Ali pa je URL napaèen.!";
?>
<script>
window.setTimeout("history.go(-1)", 3000);
</script>
<?
}
}
/////// KONEC FUNKCIJ /////////
if($_COOKIE['prijava'] == "prijavljen")
{
?>
<title>Administracija novic : Dodajanje novic</title>
<?
MYSQL_CONNECT("localhost", "user", "password") or
die (MYSQL_ERROR());
MYSQL_SELECT_DB("nuke") or
die(MYSQL_ERROR());
dodaj();
}
else
{
?>
<script>document.location.href='./prijava.php';</script>
<?
}
?>
The problem is that this scipt alow to insert the news in to the database, even if the url is not correct.
All fileds exspect vir and vir_url must contanit something.
If vir_url is filed the vir must be field to, but if vir is filed it is not necesarry to vir_url to be filed.
Bu tif vir_url is fild it must be a vaild URl with http:// at teh begiinig.
But this script inserts the news even if teh URL is not in the corrret format.
LP
JaN
www.3delavnica.com
www.ks-con.si