Desire`s Bug Topic

Gestart doorDesire70 reacties300 weergaven

71 berichten · pagina 2 van 5

Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Daarom sla ik $_POST en $_GET variabelen nooit op in losse variabelen. Zo raak je het overzicht kwijt.
Als iedereen dat nou eens deed wink
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb mijn htacces blijkbaar verkeerd.

Hier is de code, ik heb hem nu zo ver gekregen dat hij de code doorstuurt naar de index van mijn page xD en niet naar de site waar hij heen moet.
IK ben slecht in htacces.

<Files .htaccess>
order allow,deny
</Files>

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(w+)$ ./add.php?code=$code
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
RewriteRule ^(w+)$ add.php?code=$1
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zal proberen smile

toevoeging op 25 september 2012, 14:09:54:
Kan niet in mijn directadmin komen op school, ik probeer het thuis wel.

toevoeging op 25 september 2012, 15:05:05:
Nope hij linkt nog steeds door naar de index.

toevoeging op 25 september 2012, 151954:
Mijn script:

<html>
<head>
<title>l4j.nl</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div id="logo"></div>

<div id="aantal">

[COLOR= #0000BB]<?php[/COLOR]

 [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]lijst.php[/COLOR][COLOR= #007700]);[/COLOR]

?>

</div>
<div id="content">
<center><br><br><br><br><br><br><br>
[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]shortbtn[/COLOR][COLOR= #007700]])){[/COLOR]
    [COLOR= #0000BB]$url[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]];[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$url[/COLOR][COLOR= #007700])){[/COLOR]
        [URL="http://www.php.net/require"]require[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"./connect.php"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$charset[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$len[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]){[/COLOR]
            [URL="http://www.php.net/for"]for[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]<=[/COLOR] [COLOR= #0000BB]$len[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++){[/COLOR]
                [COLOR= #0000BB]$rand[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/rand"]rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]10000[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]99999[/COLOR][COLOR= #007700]) %[/COLOR] [URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$charset[/COLOR][COLOR= #007700]);[/COLOR]
                [COLOR= #0000BB]$tmp[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$charset[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$rand[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700]);[/COLOR]
                [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/base_convert"]base_convert[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$tmp[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]20[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]36[/COLOR][COLOR= #007700]);
            }[/COLOR]
            [COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM items WHERE code=$code"[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);
        }[/COLOR]
        
        [COLOR= #0000BB]$date[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"F d, Y"[/COLOR][COLOR= #007700]);[/COLOR] 
        
        [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO items VALUES (, $url, $code, $date)"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM items WHERE code=$code"[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$numrows[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/COLOR]
            [COLOR= #0000BB]$site[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SITE"[/COLOR][COLOR= #007700];[/COLOR] 
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<center>"[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Hier is je verkorte Url: <input type=text size=40 value=$site/$code>"[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<br />"[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Klik <a href=$site/$code target=_blank>hier</a> om naar je verkorte URL te gaan!"[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</center>"[/COLOR][COLOR= #007700];[/COLOR]
                        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"klik <a href=index.php>hier</a> om nog een link te verkorten"[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Je info is niet geplaatst."[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/mysql_close"]mysql_close[/URL][COLOR= #007700]();
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<script type=text/javascript>window.location = ./index.php</script>"[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<script type=text/javascript>window.location = ./index.php</script>"[/COLOR][COLOR= #007700];[/COLOR]

?>
</center>
</div>


</body>
</html>


.htacces:

<Files .htaccess>
order allow,deny
</Files>

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(w+)$ add.php?code=$1


Alleen hij linkt steeds door naar de index.. confused
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Waarom heb je in de code geen goede foutafhandeling?
Lijn 23 is bullshit. Kijk eens op Wikipedia >> SQL_Injection...
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Daar gaat de vraag niet over, ik laat het later wel door iemand controleren. Voor een beloning, nu weer
Afbeelding
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
We zijn ontopic, en het zou een beetje fijn zijn als je er wat mee deed, i.p.v. me af te snauwen.
Zo raakt mijn motivatie ook minder om je verder te helpen.
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
We zijn ontopic, en het zou een beetje fijn zijn als je er wat mee deed, i.p.v. me af te snauwen.
Zo raakt mijn motivatie ook minder om je verder te helpen.
Ik snauw je niet af, ik wil gewoon de antwoord op mijn vraag, dan kan ik verder, zodra hij af is laat ik hem door iemad controleren of de beveiliging helemaal goed is, nou ja nu weet ik dat het niet zo is, mar ik kan het niet oplossen, weet niks van foutafhandelingen niet veel iig.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Beveiliging hoor je direct te doen, en niet achteraf. Een bouwhek om een werkterrein plaats je ook niet halverwege, net als een fundering van een huis die je niet later nog even kan toevoegen.

Wees gewoon consequent om mysql_real_escape_string() te gebruiken, en plaats het niet op een backlog of ToDo-list om het ooit toe te (laten) voegen.

Verder kan je zelf prima op Google kijken naar foutafhandelingen en mysql_real_escape_string(). Ook vrij belangrijk als je script. Lees ook dit artikel eens door: http://www.phphulp.nl/php/tutorial/data-verwerking/foutafhandeling-query-sql/735/

Geloof me, veel SQL injection-hackpogingen bij bedrijven vinden op die manier plaats... Programmeurs die niet consequent bezig zijn (NOFI).

Enough...
Mijn mod_rewrite skilzz zijn niet zo heel best, maar dit zou wel moeten werken?

RewriteEngine On
RewriteRule ^(.*) add.php?code=$1
RewriteRule ^(.*)/ add.php?code=$1
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nee werkt nog niet, maar ik ga nu de foutafhandeling eerst ff doen.
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Daarom sla ik $_POST en $_GET variabelen nooit op in losse variabelen. Zo raak je het overzicht kwijt.
Als iedereen dat nou eens deed wink
Of gebruik ZEND, die doet het allemaal automatisch voor je. biggrin
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oke, ik heb een nieuwe url shortener gevonden die ik wel kan ombouwen..

Alleen die bugt ook aardig, alleen deze is beter dan de andere.. De volgende fouten heb ik:

Quote:
Notice: Undefined index: id in /home/owner/domains/DOMEIN/public_html/shorten.php on line 52

Notice: Undefined index: code in /home/owner/domains/DOMEIN//public_html/shorten.php on line 52

Bij deze code

[COLOR= #0000BB]<?php[/COLOR]
    
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]config.php[/COLOR][COLOR= #007700]);[/COLOR]

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP url shortener</title>
<style type="text/css">

#form1 p {
text-align:center;
}
</style>
</head>

<body background="images/backgroud.gif">

<div class="header"> Php URL shortener<hr /></div>
<div class="content">

[COLOR= #0000BB]<?php

$url[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]]);[/COLOR] 
[COLOR= #0000BB]$id[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/rand"]rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]10000[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]99999[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$code[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/base_convert"]base_convert[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]20[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]36[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"insert into url values("[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]real_escape[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]real_escape[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]url[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]real_escape[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]")"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$con[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Shortened url is <a href="http://site/"[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700].[/COLOR][COLOR= #DD0000]"">http://site/"[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700].[/COLOR][COLOR= #DD0000]"</a>"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_close"]mysql_close[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$con[/COLOR][COLOR= #007700]);[/COLOR]
?>




</div>


</body>
</html>


En hij slaat niets op in de database..confused
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Dan ga je uitzoeken waarom hij niets in je database stopt... dus ga je de ingevulde query echoën en kijken of die klopt.

En kijk eens naar [func]mysql_error[/func].
0
Desire

Lid · Topicstarter

Berichten
4.367
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hij slaat nu dingen op, alleen die undifened index dingen nog.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Dan ga je uitzoeken waarom hij niets in je database stopt... dus ga je de ingevulde query echoën en kijken of die klopt.
En kijk eens naar [func]mysql_error[/func].

En uiteraard ook goede foutafhandeling toevoegen..
En die undefined variabelen. Ze zijn nog niet aangemaakt. Lijkt erop dat ze niet eens meegestuurd worden met je POST.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren