[codebase] post hier je zinnige code!

Pagina: 1 2 Laatste
Acties:
  • 5.671 views sinds 30-01-2008

Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

xtentic:
PHP:
1
<?function even($num) {   // snip}?>

functie om te controlleren of een getal even of oneven is :)
Malle pietje, zeg....
daar ga je toch geen functie voor definieren :? Da's net zo iets als:
code:
1
2
3
4
function isZero ( $num )
{
   return ( $num == 0 );
}

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

  • Jelle Niemantsverdriet
  • Registratie: Februari 2000
  • Laatst online: 16:54
Op maandag 11 maart 2002 16:27 schreef drm het volgende:
daar ga je toch geen functie voor definieren :?
Los daarvan: er zit ook een foutje in dat ongetwijfeld een leuke parse error zal geven:
PHP:
1
<?function even($num) {            if ($num % 2)) {         // 1 sluithaakje te veel bij de if?>

maar goed, genoeg topic-vervuiling ;), verder met de code

Acties:
  • 0 Henk 'm!

  • VinnieM
  • Registratie: September 1999
  • Laatst online: 29-11-2024
Taal: Java
Doel: Genereer constructor, set methods en get functies aan de hand van een class met alleen datamembers.
Werkt nog niet helemaal goed met arrays, maar dat mogen jullie zelf oplossen als je er zin in hebt :)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.io.*;
import java.util.*;
import java.lang.reflect.*;

public class JavaGen {

    public static final String VERSION = "0.1a";

    public static void main(String args[]) {
        if (args.length != 1) {
            System.out.println("JavaGen " + VERSION + " - generates wrapper functions and set methods");
            System.out.println("for all declared variables (datamembers) of the specified class.");
            System.out.println("Usage: java JavaGen <CLASSFILE>");
            return;
        }
        try {
            Class c = Class.forName(args[0]);
            FileWriter fw = new FileWriter("output.txt");
            BufferedWriter bw = new BufferedWriter(fw);
            Field[] fields = c.getDeclaredFields();

            writeLine(bw, "");
            write(bw, "\tpublic " + c.getName() + "(");

            // Generate constructor-headline regarding all declared variables
            for(int i = 0; i < fields.length; i++) {
                Field field = fields[i];

                String name = field.getName();

                String type = (field.getType()).toString();
                if (type.startsWith("class")) {
                    type = type.substring(type.lastIndexOf(".") + 1);
                }

                if (i == fields.length - 1) {
                    writeLine(bw, type + " " + name + ") {");
                }
                else {
                    write(bw, type + " " + name + ", ");
                }
            }

            // Generate constructor regarding all declared variables
            for(int i = 0; i < fields.length; i++) {
                Field field = fields[i];

                writeLine(bw, "\t\tthis." + field.getName() + " = " + field.getName() + ";");
            }
             writeLine(bw, "\t}");

            // Generate wrapper-functions for all declared variables
            for(int i = 0; i < fields.length; i++) {
                writeLine(bw, "");
                Field field = fields[i];

                String name = field.getName();
                char[] chars = name.toCharArray();
                chars[0] = Character.toUpperCase(chars[0]);
                name = new String(chars);

                String type = (field.getType()).toString();
                if (type.startsWith("class")) {
                    type = type.substring(type.lastIndexOf(".") + 1);
                }

                writeLine(bw, "\tpublic " + type + " get" + name + "() {");
                writeLine(bw, "\t\treturn " + field.getName() + ";");
                writeLine(bw, "\t}");
            }

            // Generate set-methods for all declared variables
            for(int i = 0; i < fields.length; i++) {
                writeLine(bw, "");
                Field field = fields[i];

                String name = field.getName();
                char[] chars = name.toCharArray();
                chars[0] = Character.toUpperCase(chars[0]);
                name = new String(chars);

                String type = (field.getType()).toString();
                if (type.startsWith("class")) {
                    type = type.substring(type.lastIndexOf(".") + 1);
                }

                writeLine(bw, "\tpublic void set" + name + "(" + type + " " + field.getName() + ") {");
                writeLine(bw, "\t\tthis." + field.getName() + " = " + field.getName() + ";");
                writeLine(bw, "\t}");
            }
            bw.close();
            fw.close();
        }
        catch(Exception e) {
            System.err.println(e);
        }
    }

    public static void write(BufferedWriter bw, String s) throws IOException {
        bw.write(s, 0, s.length());
    }

    public static void writeLine(BufferedWriter bw, String s) throws IOException {
        bw.write(s, 0, s.length());
        bw.newLine();
    }
}

Acties:
  • 0 Henk 'm!

Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Dit script is geschreven om aantetonen hoe gemakkelijk het is om een standaard gallery script te maken. 

Mijn script ondersteund de volgende dingen. 

* Thumbnailing 
* Directory loading 
* Gallery veranderingen (qua plaatjes naast elkaar en max aantal plaatjes per pagina) 

^---- in te stellen met $prog[....] 

hoe werkt het? 

je upload dit naar je webserver in de directory van jou keuze, de commandline voor je gallery script is 

galleryscriptnaam.php?gallery=directorynaam 

vragen?... geen probleem, daarvoor heb ik email :) 

(dit is de html link versie ;))


PHP:
1
<?// show thumbnail function function makeThumb($file) {     header("Content-type: image/png");     header ("Cache-Control: no-cache");     $sz = 128;     $im = imagecreatefromjpeg("./$file");     $im_width=imageSX($im);     $im_height=imageSY($im);     // work out new sizes     if($im_width >= $im_height) {         $factor = $sz / $im_width;         $new_width = $sz;         $new_height = $im_height * $factor;     } else {         $factor = $sz / $im_height;         $new_height = $sz;         $new_width = $im_width * $factor;     }     // resize     $new_im=ImageCreate($new_width,$new_height);     ImageCopyResized($new_im, $im, 0, 0, 0, 0, $new_width, $new_height, $im_width, $im_height);     Imagepng($new_im,'',100); // quality 75     // cleanup     ImageDestroy($im);     ImageDestroy($new_im); } function showHtmlPointers() {     global $gallery, $from, $prog;     if (($from - $prog[max]) >= 1) {        echo "<a href=\"?gallery=$gallery&amp;from=" . ($from - $prog[max]) . "\">Back</a>&amp;nbsp;";     }     if ($from + $prog[max] <= $prog[files]) {        echo "<a href=\"?gallery=$gallery&amp;from=" . ($from + $prog[max]) . "\">Next</a>&amp;nbsp;";     } } function previewPicture($picture) {     global $prog;     $x = getimagesize($picture);     $width = $x[0];     $height = $x[1];     if ($height > $width) {         $percentheight = 100;         $percentwidth = round($width / ($height / 100));         $newimageheight = $prog[imageheight];         $newimagewidth = round(($prog[imagewidth] / 100) * $percentwidth);     }else{         $percentheight = round($height / ($width / 100));         $percentwidth = 100;         $newimagewidth = $prog[imagewidth];         $newimageheight = round(($prog[imageheight] / 100) * $percentheight);     }     return "[img]\"?thumb=$picture\"[/img]"; // load picture } function showPicture($picture) {     global $prog;     echo "<center>[img]\"$picture\"></center>";[/img]<a href=\"javascript:history.go(-1);\">Back</a></center>"; } function loaddir($dir){     global $filedb, $prog;     $handle = opendir($dir);     while (false !== ($file = readdir($handle))) {         if(is_dir($dir . $file)) {       // dir?!         }elseif (eregi(".nol|.gif|.bmp|.png|.jpg", $file)) {             $prog[files]++;             $filedb[file][$prog[files]] = $file;             $filedb[size][$prog[files]] = filesize($dir . $file);             $testArray =  getimagesize("./" . $dir . $file);             $filedb[height][$prog[files]] = $testArray[1];             $filedb[width][$prog[files]] = $testArray[0];         }else{         }     }     closedir($handle); } function checkPath($dir) {     if (is_dir($dir)) {         return true;     }else{         return;     } } function checkInit() {     global $prog, $filedb, $gallery, $from;     if ($from == 0) { $from = 1; }     if (strlen($gallery) > 0) {         if (checkPath($gallery)) {             loaddir("./" . $gallery . "/");             return true;         }else{             return;          }     } } // // prog // $prog[imageheight] = 128;        // hoogte van het plaatje. $prog[imagewidth] = 128;         // breedte van het plaatje. $prog[cells] = 4;                // aantal cellen. $prog[max] = 10;                // aantal plaatjes (maximaal) per pagina. if (strlen($thumb) > 0) {     makeThumb($thumb);     exit(); }elseif(strlen($display) > 0) {     showPicture($display);     exit(); } if (checkInit()) {     $prog[name] = str_replace("_", " ", $gallery);     echo "<center><h1>$prog[name]</h1></center>";     echo "<body bgcolor=#888888 text=#101818 link=#79b8c8 alink=#79b8c8 vlink=#79b8c8>";     echo "<center>";     echo "<table width=800 border=0 cellspacing=0 cellpadding=0 align=center>";     echo "<tr>";     if (($prog[max] + $from) > $prog[files]) {        $left = round(($prog[files] - $from) / $prog[cells]);                for ($i = 0; $i <= $left -1; $i++) {           echo "<table>";           echo "   <tr>";           for ($x = 0; $x <= $prog[cells] -1; $x++) {              echo "      <td align=\"center\">";                 $tmp = ($from + ($i * $prog[cells])) + $x;                 $image = $gallery . "/" . $filedb[file][$tmp];                 echo "          <a href=\"?display=" . $image . "\">" . previewPicture($image) . "</a>";              echo "      </td>";           }           echo "   </tr>";           echo "</table>";        }        $over = $prog[files] - ($from + ($left * $prog[cells]));        echo "<table>";        echo "   <tr>";        for ($x = 0; $x <= $over -1; $x++) {           echo "      <td align=\"center\">";              $tmp = ($from + ($left * $prog[cells])) + $x;              $image = $gallery . "/" . $filedb[file][$tmp];              echo "          <a href=\"?display=" . $image . "\">" . previewPicture($image) . "</a>";           echo "      </td>";        }        echo "   </tr>";        echo "</table>";        showHtmlPointers();        echo "<center>showing images " . $from . " to " . $prog[files] . " of a total of " . $prog[files] . " images</center>";        exit();     }         for ($i = 0; $i <= ($prog[max] / $prog[cells]) -1; $i++) {        echo "   <tr>";        for ($x = 0; $x <= $prog[cells] -1; $x++) {           echo "      <td align=\"center\">";              $tmp = ($from + ($i * $prog[cells])) + $x;              $image = $gallery . "/" . $filedb[file][$tmp];              echo "          <a href=\"?display=" . $image . "\">" . previewPicture($image) . "</a>";           echo "      </td>";        }        echo "   </tr>";     }     echo "</table>";     echo "<center>"; showHtmlPointers(); echo "</center>";     echo "<center>Showing images " . $from . " to " . ($from + 10) . " of a total of " . $prog[files] . " images</center>";     exit(); }else{     echo "-=[ SimpleGallery.php the gallery maker v1.0 by Xtentic]=-";     echo "<br>";     echo "<br>to use this script you need to modify the commands.";     echo "<br>?gallery = path of the files";     echo "<br>&amp;from = view page from";     echo "<br><br>Contact me at <a href=\"mailto:xtentic@hotmail.com?subject=SimpleGallery\">xtentic @ hotmail.com</a>";     exit(); } ?>

Acties:
  • 0 Henk 'm!

Verwijderd

Mijn eigen Extreem Upload Systeem
PHP:
1
<?function showForm($start, $username) {    $form[max] = 25;    $form[name] = "uploadform";    if (!isSet($start)) {        $form[start] = 5;    }else{        $form[start] = $start;    }    echo "<script language='javascript1.2'>\r\n";    echo "var varFile = new Array($form[max]);\r\n";    echo "var varComment = new Array($form[max]);\r\n";    for ($i = 0; $i <= $form[max]; $i++) {           echo "    varFile[" . $i . "] = \"\"; varComment[" . $i . "] = \"\";\r\n";    }    echo "</script>\r\n";//    echo "<body onload=\"javascript:createForm($form[start]);\">\r\n";    echo "<script language=\"JavaScript\">\r\n";    echo "function createForm(number) {\r\n";    echo "\r\n";    echo "   data = \"\";\r\n";    echo "   inter = \"'\";\r\n";    echo "   data = \"<table border=1 cellpadding=0 cellspacing=1 width=600>\";\r\n";    echo "   if ($form[max] >= number &amp;&amp; number > -1) {\r\n";    echo "      for (i=1; i <= number; i++) {\r\n";    echo "         d1 = i -1;\r\n";    echo "         data = data + \"<tr>\";\r\n";    echo "         data = data + \"<td width=20 nowrap>\" + i + \"<td width=5% nowrap>&amp;nbsp;<strong><b>F</strong></b>ile:&amp;nbsp;</td>\";\r\n";    echo "         data = data + \"<td width=45% align=center nowrap><input type='file' size='25' name='filename[\" + i + \"]' value='\" + varFile[d1] + \"'></td>\";\r\n";    echo "         data = data + \"<td width=10% nowrap align=right>&amp;nbsp;<strong><b>C</strong></b>omment:&amp;nbsp</td>\";\r\n";    echo "         data = data + \"<td width=40% nowrap><input type='text' size='40' name='filecomment[\" + i + \"]' value='\" + varComment[d1] + \"'></td>\";\r\n";    echo "         data = data + \"</tr>\";\r\n";    echo "      }\r\n";    echo "      data += \"</table>\";\r\n";    echo "      if (document.layers) {\r\n";    echo "         document.layers.cust.document.write(data);\r\n";    echo "         document.layers.cust.document.close();\r\n";    echo "      } else {\r\n";    echo "         if (document.all) {\r\n";    echo "            cust.innerHTML = data;\r\n";    echo "         }\r\n";    echo "      }\r\n";    echo "   } else {\r\n";    echo "         // error text?\r\n";    echo "   }\r\n";    echo "}\r\n";    echo "</script>\r\n";    echo "<form name=\"$form[name]\" enctype=\"multipart/form-data\" method=\"post\" action=\"$PHP_SELF\">\r\n";    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"600\">\r\n";    echo "    <tr>\r\n";    echo "        <td>Username</td>\r\n";    echo "        <td><input type=\"text\" size=\"40\" name=\"username\" value=\"$username\"></td>\r\n";    echo "    </tr>\r\n";    echo "</table>\r\n";    echo "<br>\r\n";    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"500\">\r\n";    echo "Number of uploads: <select name=\"number\" size=\"1\">\r\n";    for ($i = 2; $i <= $form[max]; $i++) {       if ($i == $form[start]) {           echo "        <option selected value=\"$i\">$i</option>\r\n";       }else{           echo "        <option value=\"$i\">$i</option>\r\n";       }    }    echo "</select>&amp;nbsp;<input type=\"button\" value=\"Update\" onclick=\"createForm($form[name].number.value);\">\r\n";    echo "</table>";    echo "<span id=\"cust\" style=\"position:relative;\"></span>\r\n";    echo "<br>\r\n";    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"600\">\r\n";    echo "    <tr>\r\n";    echo "        <input type=\"submit\" name=\"Upload\" value=\"Upload\">\r\n";    echo "        <input type=\"submit\" name=\"Clear\" value=\"Clear\">\r\n";    echo "    </tr>\r\n";    echo "</table>\r\n";    echo "</form>\r\n";    echo "\r\n";    echo "<script language=\"javascript\">createForm($form[start]);</script>\"\r\n";    echo "\r\n";}$iPath = "./upload/images/";$oPath = "./upload/other/";if ($Upload == "Upload") {   for ($i = 1; $i <= count($filename_name); $i++) {       if ($filename_size[$i] != 0) {           $typ = $filename_type[$i];           if (eregi("image", $typ) > 0) {               echo "<li><strong><b>$filename_name[$i]</b></strong> is succesfully uploaded to my server!</li><br>";               copy("$filename[$i]", "$iPath$filename_name[$i]") or die("Couldn't copy the file!");               $path = $iPath . $filename_name[$i] . ".txt";               $cfile = @fopen ($path, "a");               @fwrite ($cfile, "$username###$filename_name[$i]###$filecomment[$i]###$REMOTE_ADDR\r\n");               @fclose ($cfile);           }else{               echo "<li><strong><b>$filename_name[$i]</b></strong> is succesfully uploaded to my server!</li><br>";               copy("$filename[$i]", "$oPath$filename_name[$i]") or die("Couldn't copy the file!");               $path = $oPath . $filename_name[$i] . ".txt";               $cfile = @fopen ($path, "a");               @fwrite ($cfile, "$username###$filename_name[$i]###$filecomment[$i]###$REMOTE_ADDR\r\n");               @fclose ($cfile);           }       }   }}if (!isSet($number)) { $number = 5; }if (!isSet($username)) { $username = "Unknown"; }showForm($number, $username);?>

Erg simpel en zeer leuk om te implementeren!, wanneer je dit gebruikt stel me ff op de hoogte. Vind het namelijk erg leuk om te zien wat er met mijn spul gebeurd! :)

Greetz, Xtentic

Acties:
  • 0 Henk 'm!

Verwijderd

Ik heb met classes een timer in php gemaakt waarmee de parse time mee berekent kan worden. Het voordeel is dat deze in OOP is en dus meerdere objecten als teller gebruikt kunnen worden. Ik heb ook een pauze/stop functie er in gebouwd.

Dit is het eerste ding wat ik in OOP gemaakt heb, ik vind hem zelf wel handig.
PHP:
1
<?/*    Made by:    Julien Rentrop / julien@interned.com    Version:    0.5 (Seems to work ok)    Date:        17/03/2002        Description:    Use this class to figure out the parse time your code takes.        Create different instances if you want to get the parsetime of different parts of code.    You can also use the pausetime if you want to skip some code and add up parsetime    in a later set of code or just stop the timer and show the time it took in the end.*/class Timer{    var $BeginTime = 0; //Contains the start time    var $ParseTime = 0; //Stores the parse time when the timer has been paused    var $Paused = FALSE;        function Timer($start) //Constructor. Automatically start timing if $start is TRUE.    {        if ($start)        {            $this->BeginTime = $this->getTime();            $this->Paused = FALSE;        }        else            $this->Paused = TRUE;    }        function getTime() //The clock    {        $time = explode(" ", microtime());        return (double)$time[0] + (double)$time[1];    }        function pauseTimer() //Stop the clock    {        if (!$this->Paused)        {            $this->Paused = TRUE;            $this->ParseTime = $this->ParseTime + $this->getTime() - $this->BeginTime;        }    }        function startTimer() //Continue the clock    {        $this->Paused = FALSE;        $this->BeginTime = $this->getTime();    }        function getParseTime() //Get the time    {        if ($this->Paused)            return $this->ParseTime;        else            return $this->getTime() - $this->BeginTime + $this->ParseTime;    }}?>

Acties:
  • 0 Henk 'm!

Verwijderd

Script: VarNav 0.1 béta
Doel: Het browsen door een var (een var dus opdelen in meerdere pagina's)
Taal: Php of course ;)
PHP:
1
<?/* VarNav 0.1 béta door Markuz */$text = "blaat|blaat2|blaat3|blaat4"; // de text$explodeer = explode("|",$text); // exploderen op "|"$aantal = count($explodeer); // het aantal delen tellenif(!$pagina) {    $pagina = "1";}$vorige = $pagina - 1;if($vorige == "0" || $pagina == "") {    echo "< ";}else {    echo "<a href=\"$PHP_SELF?pagina=$vorige\"><</a> ";}for($x = 1; $x < $aantal + 1; $x++) {    if($x == "$aantal")     {        $streep = "";    }    else     {        $streep = "|";    }    if($x == "$pagina")     {        $b = "<b>";        $b2 = "</b>";    }    else     {        if($x != "$pagina")         {            $b = "";            $b2 = "";        }    }    echo "<a href=\"$PHP_SELF?pagina=" . $x . "\">" . $b . $x . $b2 . "</a> $streep ";     // laat de nummers zien, bijv: 1 | 2 | 3 enz.}$volgende = $pagina + 1;if($volgende - 1 == "$aantal") {    echo "> ";}else {    echo "<a href=\"$PHP_SELF?pagina=$volgende\">></a> ";}for($x = 1; $x < $aantal + 1; $x++) {    if($pagina == "$x")     {        echo "<p>" . $explodeer[$x - 1] . "</p>";    }}?>

<font color=red>indent@D2k</font>

Acties:
  • 0 Henk 'm!

Verwijderd

Script: Sleutel generator
Doel: Sleutel genereren
Taal: Php
PHP:
1
<?function sleutel($ptijd = 0) {    $uab = 57;    $lab = 48;    $mic = microtime();    $smic = substr($mic,1,2);    $emic = substr($mic,4,6);    mt_srand ((double)microtime() * 1000000);    $ch = (mt_rand() % ($uab-$lab)) + $lab;    $po = strpos($emic, chr($ch));    $emica = substr($emic, 0, $po);    $emicb = substr($emic, $po, strlen($emic));    $out = $emica.$smic.$emicb;$out = md5(crypt($out));    return $out;}?>

Deze heb ik niet zelf geschreven, wie wel, geen idee...

Maar deze is wel ongelofelijk random :)
<font color=red>indent@D2k</font>

Acties:
  • 0 Henk 'm!

  • Valium
  • Registratie: Oktober 1999
  • Laatst online: 27-09 09:35

Valium

- rustig maar -

Taal:Bash
Doel:Autocompilescript voor Debian GNU/Linux.
Uitleg:
Dit scriptje is een wrapper-script om een debian-systeem zeer comfortabel te kunnen voorzien van eigengecompileerde pakketten. Het script is alleen nuttig als de pakketten "pentium-builder" en "build-essential" geinstalleerd zijn.
Het zorgt ervoor dat je systeem nette pakketten heeft met toch voor jouw arch (i686, athlon e.d.) geoptimaliseerde code.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh

case "$1" in
    install)
      if [ ! -x /tmp/debian-cast ]; then
          echo "Let op eventuele foutmeldingen en rapporteer die"
          echo "bij bugs.debian.org (build-dep en sourcebuild problemen)"
          echo "Afhankelijkheden wordt opgehaald."
          apt-get build-dep $2
          echo "Werkmap wordt gemaakt."
          mkdir /tmp/debian-cast
    else
        echo "Map bestaat nog."
    fi
        cd /tmp/debian-cast
    if [ ! -x /tmp/debian-cast/readytocompile ]; then
          echo "Broncode wordt opgehaald."
        apt-get source $2
          werkmap=`ls -A -l | grep drwx | awk '{print $9}' | head -n 1`
        if ls -A -l | grep drwx | awk '{print $9}'; then
          echo "Configuratie wordt aangepast."
          cd $werkmap
#       Dit leuke stukje vervangt in de changelog het versienummer door versienummer.owncompile
#       Hierdoor zie je dat het om een eigengebrouwen pakket gaat.
          mv /tmp/debian-cast/$werkmap/debian/changelog \
        /tmp/debian-cast/$werkmap/debian/changelog.old
          cat /tmp/debian-cast/$werkmap/debian/changelog.old | \
        sed 's/\(.*\)\(-\)\([0-9]*\))/\1\2\3.owncompile)/' > /tmp/debian-cast/$werkmap/debian/changelog
          rm /tmp/debian-cast/$werkmap/debian/changelog.old
          echo $werkmap > /tmp/debian-cast/readytocompile

        else
        echo "Ik kon geen werkmap vinden. Compileren afgebroken."
        exit 0
        fi
    fi
    echo ""
    echo "==============================================="
    echo -n "Te compileren pakket: "
    cat /tmp/debian-cast/readytocompile
    set | grep DEBIAN_BUILDARCH
    head -n 1 /tmp/debian-cast/$werkmap/debian/changelog
    echo "==============================================="
    sleep 2
#   Dit is de werkelijke opdracht om het pakket te compileren.
    debian/rules binary

    cd /tmp/debian-cast
    echo "Pakketten worden geinstalleerd."
    ls -A1 /tmp/debian-cast/*.deb
      if dpkg -i /tmp/debian-cast/*.deb; then
        echo "Installatie voltooid."
        mv /tmp/debian-cast/*.deb /var/cache/apt/archives/
        echo "Werkmap wordt verwijderd."
        cd /tmp
        rm -rf /tmp/debian-cast
          echo "klaar."
      else
        echo "Fout opgetreden bij installatie."
        echo "Ik verwijder de werkmap nog niet."
      fi
      ;;
    clean)
      rm -rf /tmp/debian-cast
      ;;
    *)
      echo "gebruik: cast install <pakketnaam>, cast clean."
      exit 1
      ;;
esac

Help mee met het vertalen van GNOME. | #nos op irc.tweakers.net voor directe hulp.


Acties:
  • 0 Henk 'm!

  • Juup
  • Registratie: Februari 2000
  • Niet online
Valium> Volgens my is dit geen bash script maar een gewoon shell script. Zie eerste regel van je script.

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.


Acties:
  • 0 Henk 'm!

  • Valium
  • Registratie: Oktober 1999
  • Laatst online: 27-09 09:35

Valium

- rustig maar -

Op woensdag 27 maart 2002 10:32 schreef Jaaap het volgende:
Valium> Volgens my is dit geen bash script maar een gewoon shell script. Zie eerste regel van je script.
Maar de meeste mensen gebruiken bash als shell, dus eigenlijk is het een soort van synoniem.
(sec heb je wel gelijk ja.)

Ik heb trouwens een nieuwe versie online staan: cast

Help mee met het vertalen van GNOME. | #nos op irc.tweakers.net voor directe hulp.


Acties:
  • 0 Henk 'm!

Verwijderd

Code = PHP
Doel = datum converten (verbeterd)
PHP:
1
<?function showdate($date) {  $maandarray = array("1"=>"januari","februari","maart","april","mei","juni","juli","augustus","september","october","november","december");  $dagarray = array("0"=>"zondag","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag");  $cdate = date('w-j-n-Y', strtotime($date)); list($day, $dom, $month, $year) = split('-', $cdate);    return $dagarray[$day].', '.$dom.' '.$maandarray[$month].' '.$year; }?>

Aanroepen met
PHP:
1
<?$datum =&amp; showdate(date('Y-m-d'));print $datum;?>

Acties:
  • 0 Henk 'm!

Verwijderd

Op maandag 11 maart 2002 15:28 schreef pistole het volgende:
code:
1
2
3
function qfix(str)
  qfix=replace(str, "'", "'')
end function
Je bent een " vergeten, dus:
code:
1
  qfix=replace(str, "'", "''")

Acties:
  • 0 Henk 'm!

  • Juup
  • Registratie: Februari 2000
  • Niet online
Taal: Perl
Doel: Het berekenen van Pi met veel decimalen. Met het snelste algoritme bekend.
Usage: Saven als pi.pl, chmodden naar 755 (chmod 755 pi.pl) en runnen maar! Staat nu ingesteld op 10 iteraties, maar als je Math::BigFloat gebruikt kun je zoveel decimalen doorfietsen als je wilt (nog niet helemaal werkend met BigFloat).
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!perl -Tw
 
use strict;
#use Math::BigFloat;
 
#my $pi = Math::BigFloat->new("0.0");
#my $sixteenn = Math::BigFloat->new("16.0");
 
my $pi = 0;
my $sixteenn = 16;
for (my $i = 0; $i < 10; $i++)
{ my $eighti = 8*$i;
  my $tmp = 4/($eighti + 1);
  $tmp -= 2/($eighti + 4);
  $tmp -= 1/($eighti + 5);
  $tmp -= 1/($eighti + 6);
  $sixteenn /= 16;
  $tmp *= $sixteenn;
  $pi += $tmp;
  print "\$pi: $pi\n";
}
print "\n";

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.


Acties:
  • 0 Henk 'm!

  • Juup
  • Registratie: Februari 2000
  • Niet online
Zeer goede Perl scripts (very basic stuff) is te vinden op:
http://nms-cgi.sourceforge.net/ Bebaseerd op Matt's script archive maar dan goed.
Bijvoorbeeld:

Countdown script
Formmail
Guestbook
Random Image/Link/Text
Searchscript
Counter
Clock

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.


Acties:
  • 0 Henk 'm!

Verwijderd

Taal:Javascript
Doel:Getal afronden
Omsc:Rond een getal af. De variabele getal moet wel een string zijn.
code:
1
getal = (parseInt(getal.substring((getal.indexOf(".") + 1),(getal.indexOf(".") + 2))) >= 5)? (parseInt(getal.substring(0,getal.indexOf(".")))+1):getal.substring(0,getal.indexOf("."))

Pas geleden gemaakt voor de fun.....

Acties:
  • 0 Henk 'm!

  • RickN
  • Registratie: December 2001
  • Laatst online: 14-06 10:52
Op woensdag 27 maart 2002 16:00 schreef Jaaap het volgende:
Taal: Perl
Doel: Het berekenen van Pi met veel decimalen. Met het snelste algoritme bekend.
Usage: Saven als pi.pl, chmodden naar 755 (chmod 755 pi.pl) en runnen maar! Staat nu ingesteld op 10 iteraties, maar als je Math::BigFloat gebruikt kun je zoveel decimalen doorfietsen als je wilt (nog niet helemaal werkend met BigFloat).
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!perl -Tw
 
use strict;
#use Math::BigFloat;
 
#my $pi = Math::BigFloat->new("0.0");
#my $sixteenn = Math::BigFloat->new("16.0");
 
my $pi = 0;
my $sixteenn = 16;
for (my $i = 0; $i < 10; $i++)
{ my $eighti = 8*$i;
  my $tmp = 4/($eighti + 1);
  $tmp -= 2/($eighti + 4);
  $tmp -= 1/($eighti + 5);
  $tmp -= 1/($eighti + 6);
  $sixteenn /= 16;
  $tmp *= $sixteenn;
  $pi += $tmp;
  print "\$pi: $pi\n";
}
print "\n";
Dit is niet zo snel hoor, dit geeft je 1 of 2 extra correcte decimalen per iteratie. Er zijn series die VEEEEEEEEEEEEL sneller convergeren. Dit algoritme is vooral goed om het n-de cijfer in de hexadecimale representatie van Pi te berekenen, zonder alle voorafgaande cijfers te moeten berekenen. Maar ja, hexadecimale representatie is natuurlijk niet zo cool.

He who knows only his own side of the case knows little of that.


Acties:
  • 0 Henk 'm!

Verwijderd

Taal: ASP
Doel: Inloggen van mensen naar website via mooi login menu

Login1.asp (passwords zijn: TEST & TEST2 (denk aan hoofdletters!)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<html>

<head>
<title>IIS</title>
</head>

<body bgcolor="#E6E6E6">
<p><form action="Login.asp">
      <font face="Verdana" color="#666666"><b>
      <select size="1" name="user">
      <option selected>&lt;.................Kies een account.................&gt;
      </option>
      <option value="Kees de Koning">Tester 1 (Admin.)</option>
      <option value="Tim Oskam">Tester 2 (Admin.)</option>
      </select></b></font>
<p>
      <font face="Verdana"><b><font color="#666666">
      <input type="password" name="pass" size="33"></font></b></font>     
</p>
<p>
      <font size="1" face="Verdana">
      <input type="checkbox" name="check" value="ok" style="float: left"> </font><span lang="en-us"><font size="2" face="Verdana">Password
opslaan</font></span></p>
<p>
      <button name="submit" type="submit" style="width: 185; height: 25">
 &nbsp;Inloggen! </p>
</form>
</body></html>

Login.asp
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<% 

'Gemaakt door de enige echte Bit.Neuker -> KC!

dim username
dim password
dim check
username = request.Form ("user")
password = request.Form ("pass")
check = request.form ("check")
fout = "&quot;kees&quot;"
userfout ="&quot;gek&quot;"
        if (username) = "<.................Kies een account.................>" then
            response.redirect ("error.html")
        end if
        
    
    if (username) = "Kees de Koning" AND (password) = "TEST" OR (username) = "Tim Oskam" AND (password) = "TEST2" then 
        
        
        
        if (check) = "ok" then
            response.write ("<body bgcolor='#E6E6E6'><p>&nbsp;</p><p align='center'><b><font face='Verdana' color='#FF0000'>Inloggen gelukt!</font></b></p><div align=center><center>     <table border=1 cellpadding=0 cellspacing=0 style='padding:0; border-collapse:collapse; border-left-style:outset; border-left-width:0; border-right-style:outset; border-right-width:0; border-top-style:outset; border-top-width:1; border-bottom-style:outset; border-bottom-width:1' collapse bordercolor=#111111 width=426 height=165 id=AutoNumber1>    <tr>               <td width=5 height=45 style='border-left-style:; border-left:1px solid #111111; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' solid; border-left-width: 1; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>    <p align=justify></td>              <td width=44 height=47 style='border-left-style:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>  <p align=center>    [img]'error2.gif'[/img]</td>                <td width=351 height=47 style='border-left-style:; border-right:1px solid #111111; border-left-style:none; border-left-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' none; border-left-width: medium; border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>     <font face='Verdana' size='2'>&nbsp;Beste <B>" & username & " </b>het inloggen is gelukt...</font></td>    </tr>      <tr>      <td width='100%' height=17 style='border-left-style:; border-left:1px solid #111111; border-right:1px none #111111; border-top-style:none; border-top-width:medium; border-bottom-style:none; border-bottom-width:medium' bgcolor=#DDDAD5 colspan='3'>        <div style='border-right-style: solid; border-right-width: 1; padding-right: 4'>    <hr color='#999999' width='95%'>    </div>  </td>             </tr>    <tr>                         <td width=3 height=62 style='border-left-color:; border-left:1px solid #111111; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; ' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium bgcolor=#DDDAD5>        <font face='Verdana' size='2'>&nbsp; </font></td>                         <td width=417 height=62 style='border-left-color:; border-right:1px solid #111111; border-left-style:none; border-left-width:medium; border-top-style:none; border-top-width:medium; ' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium colspan=2 bgcolor=#DDDAD5>     <font face='Verdana' size='2'><b><font color='#FF0000'>Letop:</font><br>    </b>Om veiligheidsredenen is het niet gelukt om je password op te slaan...!</font></td>    </tr>    <tr>    <td width=3 height=19 style='border-left-color:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; ' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium>       </td>                         <td width=417 height=19 style='border-left-color:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; ' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium colspan=2>     &nbsp;</td>   </tr>    <tr> <td width=3 height=17 style='border-left-color:; border-left:1px solid #111111; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:solid; border-bottom-width:1' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium bgcolor=#DDDAD5>      &nbsp;</td>                       <td width=417 height=17 style='border-left-color:; border-right:1px solid #111111; border-left-style:none; border-left-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:solid; border-bottom-width:1' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium colspan=2 bgcolor=#DDDAD5>       <font size='2' face='Verdana'>Klik hier om   verder te gaan...</font></td>      </tr>  </table>  </center></div>")
        else
            response.write ("<body bgcolor='#E6E6E6'><p>&nbsp;</p><p align='center'><b><font face='Verdana' color='#FF0000'>Inloggen gelukt!</font></b></p><div align=center><center>       <table border=1 cellpadding=0 cellspacing=0 style='padding:0; border-collapse:collapse; border-left-style:outset; border-left-width:0; border-right-style:outset; border-right-width:0; border-top-style:outset; border-top-width:1; border-bottom-style:outset; border-bottom-width:1' collapse bordercolor=#111111 width=426 height=94 id=AutoNumber1>    <tr>                    <td width=5 height=1 style='border-left-style:; border-left:1px solid #111111; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' solid; border-left-width: 1; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>   <p align=justify></td>                  <td width=44 height=1 style='border-left-style:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>   <p align=center>    [img]'error2.gif'[/img]</td>                    <td width=351 height=1 style='border-left-style:; border-right:1px solid #111111; border-left-style:none; border-left-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' none; border-left-width: medium; border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>      <font face='Verdana' size='2'>&nbsp;Beste <B>" & username & " </b> het inloggen is gelukt...</font></td>    </tr>     <tr>  <td width=3 height=19 style='border-left-color:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; ' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium>       </td>                         <td width=417 height=19 style='border-left-color:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; ' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium colspan=2>     &nbsp;</td>   </tr>    <tr>     <td width=3 height=12 style='border-left-color:; border-left:1px solid #111111; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:solid; border-bottom-width:1' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium bgcolor=#DDDAD5>      &nbsp;</td>                         <td width=417 height=12 style='border-left-color:; border-right:1px solid #111111; border-left-style:none; border-left-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:solid; border-bottom-width:1' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium colspan=2 bgcolor=#DDDAD5>         <font size='2' face='Verdana'>Klik hier om   verder te gaan...</font></td>      </tr>  </table>  </center></div>")
        end if
        

    Else
        response.write ("<body bgcolor='#E6E6E6'><p>&nbsp;</p><p align='center'><b><font face='Verdana' color='#FF0000'>Error 403:18 - Access denied (<font size='2'>MS IIS 5.1</font>)</font></b></p><div align=center><center>  <table border=1 cellpadding=0 cellspacing=0 style='border-style:outset; border-width:1; padding:0; border-collapse:collapse' collapse bordercolor=#111111 width=426 height=91 id=AutoNumber1>    <tr>         <td width=5 height=5 style='border-left-style:; border-left-style:solid; border-left-width:1; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' solid; border-left-width: 1; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>    <p align=justify></td>            <td width=44 height=51 style='border-left-style:; border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5>    <p align=center>    [img]'error2.gif'[/img]</td>            <td width=351 height=51 style='border-left-style:; border-left-style:none; border-left-width:medium; border-right-style:solid; border-right-width:1; border-top-style:solid; border-top-width:1; border-bottom-style:none; border-bottom-width:medium' none; border-left-width: medium; border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1; border-bottom-style: none; border-bottom-width: medium bgcolor=#DDDAD5> <font size=2 face=Verdana>Er is een verkeerd wachtwoord ingevuld om als <B>" & username & "</b> in te loggen...</font></td>    </tr>    <tr>              <td width=426 height=36 style='border-left-color:; border-left-style:solid; border-left-width:1; border-right-style:solid; border-right-width:1; border-top-style:none; border-top-width:medium; border-bottom-style:solid; border-bottom-width:1' #111111; border-left-width: 1; border-right-color: #111111; border-right-width: 1; border-top-style: none; border-top-width: medium colspan=3 bgcolor=#DDDAD5> <font size=2 face=Verdana>&nbsp;&nbsp;Klik op vorige om opnieuw je wachtwoord in te vullen...</font></td>    </tr>  </table>  </center></div>")
         end if
%>

Acties:
  • 0 Henk 'm!

  • ajvdvegt
  • Registratie: Maart 2000
  • Laatst online: 27-09 18:28
Op zaterdag 30 maart 2002 17:01 schreef Bit.neuker een stuk code.
Ik snap dat het niet de bedoeling is om hier mensen af te kraken, maar dat is wel zo ongeveer de meest inflexibele code die ik in tijden gezien heb. De wachtwoorden zijn niet makkelijk uitbreidbaar en ze staan kaal in de code.

Ook lijkt het me HEEEEEEEL handig om een .css bestandje te maken voor al je opmaakcodes ipv. die steeds te 'write'-en. :+
Hier kan je alle info over CSS vinden je nodig hebt, maar aangezien je de codes al kent lijkt het maken van een .css bestand me een kleine moeite.

I don't kill flies, but I like to mess with their minds. I hold them above globes. They freak out and yell "Whooa, I'm *way* too high." -- Bruce Baum


Acties:
  • 0 Henk 'm!

  • rookie
  • Registratie: Februari 2000
  • Niet online
PHP:
1
<?  function randompasswd() {    //A password generator thats creates pronounceable random words.    $VOWEL = array(1 => "A", 2 => "E", 3 => "I", 4 => "O", 5 => "U", 6 => "Y");    $vowel = array(1 => "a", 2 => "e", 3 => "i", 4 => "o", 5 => "u", 6 => "y");    $consonant = array(      1 => "b", 2 => "c", 3 => "d", 4 => "f", 5 => "g",       6 => "h", 7 => "j", 8 => "k", 9 => "l", 10=> "m",      11=> "n", 12=> "p", 13=> "q", 14=> "r", 15=> "s",      16=> "t", 17=> "v", 18=> "w", 19=> "x", 20=> "z"    );    return (string) $VOWEL[rand(1,5)].$consonant[rand(1,20)].$vowel[rand(1,5)].$consonant[rand(1,20)].$vowel[rand(1,5)].rand(1,9);  }?>

Acties:
  • 0 Henk 'm!

Verwijderd

Delphi/API

Verkrijg eigenaar en domein van een bestand.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'
function GetFileOwner(var Domain, Username: string): Boolean;
var
  FFileName: string;
  SecDescr: PSecurityDescriptor; 
  SizeNeeded, SizeNeeded2: DWORD; 
  OwnerSID: PSID;
  OwnerDefault: BOOL; 
  OwnerName, DomainName: PChar; 
  OwnerType: SID_NAME_USE; 
begin
  // het gaat om dit bestand
  FFileName := 'c:\bla.doc';

  GetFileOwner := False;
  GetMem(SecDescr, 1024); 
  GetMem(OwnerSID, SizeOf(PSID));
  GetMem(OwnerName, 1024); 
  GetMem(DomainName, 1024); 
  try 
    if not GetFileSecurity(PChar(FFileName),
    OWNER_SECURITY_INFORMATION, 
    SecDescr, 1024, SizeNeeded) then 
    Exit; 
    if not GetSecurityDescriptorOwner(SecDescr, 
    OwnerSID, OwnerDefault) then 
    Exit; 
    SizeNeeded  := 1024; 
    SizeNeeded2 := 1024; 
    if not LookupAccountSID(nil, OwnerSID, OwnerName, 
    SizeNeeded, DomainName, SizeNeeded2, OwnerType) then
    Exit; 
    Domain   := DomainName; 
    Username := OwnerName; 
  finally 
    FreeMem(SecDescr); 
    FreeMem(OwnerName); 
    FreeMem(DomainName);
  end; 
  GetFileOwner := True; 
end;

Acties:
  • 0 Henk 'm!

  • Orphix
  • Registratie: Februari 2000
  • Niet online
Taal: C#
Doel: Het genereren van een typische MD5 Hash van een gegeven string. De standaard hash functie in .NET retourneert byte-waardes. Deze functie vertaalt dit naar een leesbare (ASCII) string zoals vaak de bedoeling is (wachtwoorden, msn, etc).
code:
1
2
3
4
5
6
7
8
9
10
11
12
protected string HashMD5(string input)
{
    byte[] result = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(TextEncoding.GetBytes(input));
    string output = "";
                              
    for (int i = 0; i < result.Length; i++) 
    {           
        // convert from hexa-decimal to character
        output += (result[i]).ToString( "x2" );
    }
    return output;
}

Acties:
  • 0 Henk 'm!

Verwijderd

/me *

Ben ff twee daagjes bezig geweest een fatsoenlijke fotosite aan te maken in PHP/mySQL, en aangezien deze nu zelfs redelijk fatsoenlijk werkt kan ik 'em net zo goed hier posten. Ik doe er toch niet veel zinnigs mee. :Y).

Het doel van deze code is om een aantal mensen ('user') elk een eigen identiteit te geven in de database en per gebruiker foto's te kunnen neerzetten. Bezoekers kunnen via users.php een persoon selecteren en dan per persoon foto's bekijken. Administration gaat via admin.php (username/password protected natuurlijk).

Wat heb je nodig:
• bakkie met apache, mySQL en PHP
• SQL database ("real_database") met twee tabellen: 'foto' en 'user':
• twee SQL users, eentje ('anonymous') met SELECT access en eentje ("real_username") met SELECT, INSERT, UPDATE en DELETE access
• twee subdirectories in de PHP directory: fotos/ en fotos_thumbnails/ (hier worden de fotos'/thumbnails geplaatst)

real_username, real_database en real_passworde zijn gedefinieerd in login.php.

Database layout:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mysql> DESCRIBE user;
+----------+-----------------+------+-----+---------+----------------+
| Field    | Type       | Null | Key | Default | Extra      |
+----------+-----------------+------+-----+---------+----------------+
| userID   | int(4) unsigned |  | PRI | NULL    | auto_increment |
| nick     | varchar(255)    |  | UNI |    |            |
| name     | varchar(255)    | YES  |     | NULL    |           |
| email    | varchar(255)    | YES  |     | NULL    |           |
| homepage | varchar(255)    | YES  |     | NULL    |           |
+----------+-----------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

mysql> DESCRIBE foto;
+--------------+-----------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra      |
+--------------+-----------------+------+-----+---------+----------------+
| fotoID     | int(4) unsigned |    | PRI | NULL    | auto_increment |
| userID     | int(4) unsigned | YES  |     | NULL    |         |
| beschrijving | varchar(255)    | YES  | MUL | NULL    |           |
| nemer   | varchar(255)    | YES  |     | NULL    |            |
| path     | varchar(255)    |  |     |    |            |
| datum   | date        | YES  |     | NULL    |            |
+--------------+-----------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)

mysql>

Code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[rbultje@gizmo dutch]$ cat users.php
<?php
  include "script/page_setup.php";

  page_header("#dutch bezoekers");

  // Connecting, selecting database
  $link = mysql_connect("localhost", "anonymous")
    or die("Could not connect to MySQL");
  mysql_select_db("dutch")
    or die("Could not select dutch database");

  // get the paper table
  $query = "SELECT userID,nick
        FROM user ORDER BY nick";
  $result = mysql_query($query)
    or die("Query failed");

  // Printing results in HTML
  print "<h1>Users:</h1>";
  while ($line = mysql_fetch_row($result)) {
    // nick
    print "\t<a href=\"profile.php?user=$line[0]\">$line[1]</a><br>\n";
  }
  // Free results
  mysql_free_result($result);

  // Closing connection
  mysql_close($link);

  page_footer();
?>


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[rbultje@gizmo dutch]$ cat profile.php
<?php
  include "script/page_setup.php";

  page_header("Profiel");

  // Connecting, selecting database
  $link = mysql_connect("localhost", "anonymous")
    or die("Could not connect to MySQL");
  mysql_select_db("dutch")
    or die("Could not select groupware database");

  // get the paper table
  $query = "SELECT nick, name, email, homepage
        FROM user
        WHERE userID = $user";
  $result = mysql_query($query)
    or die("Query failed");

  // Printing results in HTML
  //print "<h1>Profile:</h1>";

  $line = mysql_fetch_row($result);

  print "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\" bgcolor=\"#f0f0f0\">\n\t<tr>\n\t\t<td>\n";

  //info
  print "\t<b>Nick: </b>$line[0]<br>\n";

  if ($line[1]!=null) {
    print "\t<b>Name: </b>$line[1]<br>\n";
  }
  if ($line[2]!=null) {
    print "\t<b>Email: </b><a href=\"mailto:$line[2]\">$line[2]</a><br>\n";
  }
  if ($line[3]!=null) {
    print "\t<b>Homepage: </b><a href=\"$line[3]\">$line[3]</a><br>\n";
  }

  print "\t\t</td>\n\t</tr>\n</table>\n<p>\n";

  // Free results
  mysql_free_result($result);

  // Foto's
  $query = "SELECT fotoID,path
        FROM foto
        WHERE foto.userID = $user";
  $result = mysql_query($query)
    or die("Query failed");

  while ($line = mysql_fetch_row($result)) {
    print "<a href=\"foto.php?foto=$line[0]\">";
    print "[img]\"fotos_thumbnails/$line[1]\">";
[/img]\n";
  }

  // Free result
  mysql_free_result($result);

  // Closing connection
  mysql_close($link);

  page_footer();
?>


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[rbultje@gizmo dutch]$ cat foto.php
<?php
  include "script/page_setup.php";

  page_header("Foto");

  // Connecting, selecting database
  $link = mysql_connect("localhost", "anonymous")
    or die("Could not connect to MySQL");
  mysql_select_db("dutch")
    or die("Could not select groupware database");

  // get the paper table
  $query = "SELECT user.nick,
             foto.beschrijving, foto.nemer,
             foto.datum, foto.path
        FROM user,foto
        WHERE user.userID = foto.userID AND
            foto.fotoID = $foto";
  $result = mysql_query($query)
    or die("Query failed");

  // Printing results in HTML
  //print "<h1>Foto:</h1>";

  $line = mysql_fetch_row($result);

  print "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\" bgcolor=\"#f0f0f0\">\n\t<tr>\n\t\t<td>\n";

  // subject
  print "\t<b>Wie: </b>$line[0]<br>\n";

  // beschrijving
  if ($line[1]!=null) {
    print "\t<b>Wat: </b>$line[1]<br>\n";
  }

  // nemer
  if ($line[2]!=null) {
    print "\t<b>Door: </b>$line[2]<br>\n";
  }

  // datum
  if ($line[3]!=null) {
    print "\t<b>Datum: </b>$line[3]<br>\n";
  }

  print "\t\t</td>\n\t</tr>\n</table>\n<p>\n";

  // foto
  print "[img]\"fotos/$line[4]\"[/img]\n";

  // Free results
  mysql_free_result($result);

  // Closing connection
  mysql_close($link);

  page_footer();
?>


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
[rbultje@gizmo dutch]$ cat admin.php
<?php
  include "script/page_setup.php";
  include "login.php";

  function list_users()
  {
    // Connecting, selecting database
    $link = mysql_connect("localhost", "anonymous")
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    $query = "SELECT userID,nick
          FROM user ORDER BY nick";

    $result = mysql_query($query)
    or die("Query '$query' failed");

    // Printing results in HTML form language
    print "<select size=\"6\" name=\"userID\">\n";
    while ($line = mysql_fetch_row($result)) {
    print "<option value=\"$line[0]\">$line[1]</option>\n";
    }
    print "</select>\n";

    // close result
    mysql_free_result($result);

    // close session
    mysql_close($link);
  }

  function print_user($userID)
  {
    if ($userID)
    {
    // Connecting, selecting database
    $link = mysql_connect("localhost", "anonymous")
      or die("Could not connect to MySQL");
    mysql_select_db(real_database)
      or die("Could not select database");

    // get the paper table
    $query = "SELECT userID,nick,name,email,homepage
            FROM user WHERE userID = $userID";
    $result = mysql_query($query)
      or die("Query '$query' failed");

    $line = mysql_fetch_row($result);
    }

    print "<input type=\"hidden\" name=\"userID\" value=\"$userID\">\n";

    print "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Nickname: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"nickname\" value=\"$line[1]\"></td>\n";
    print "\t</tr>\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Naam: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"naam\"value=\"$line[2]\"></td>\n";
    print "\t</tr>\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Email: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"email\" value=\"$line[3]\"></td>\n";
    print "\t</tr>\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Homepage: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"homepage\" value=\"$line[4]\"></td>\n";
    print "\t</tr>\n";
    print "</table>\n";

    if ($userID)
    {
    // free result
    mysql_free_result($result);

    //close session
    mysql_close($link);
    }
  }

  function remove_user($userID)
  {
    include "login.php";

    // Connecting and selecting database
    $link = mysql_connect("localhost", real_username, real_password)
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    // selecteer foto's van die user en remove
    $query = "SELECT fotoID
          FROM foto
          WHERE userID = $userID";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    while ($line = mysql_fetch_row($result))
    remove_foto($line[0]);
    mysql_free_result($result);

    $query = "DELETE FROM user
          WHERE userID = $userID";
    $result = mysql_query($query)
    or die("Query '$query' failed");
   print "User removed<p>\n";

    // close session
    mysql_close($link);
  }

  function add_user($nick,$name,$email,$homepage)
  {
    include "login.php";

    // Connecting and selecting database
    $link = mysql_connect("localhost", real_username, real_password)
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    $query = "INSERT INTO user
          VALUES(null,'$nick','$name','$email','$homepage')";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    print "User added<p>\n";

    // close session
    mysql_close($link);
  }

  function modify_user($userID,$nick,$name,$email,$homepage)
  {
    include "login.php";

    // Connecting and selecting database
    $link = mysql_connect("localhost", real_username, real_password)
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    $query = "UPDATE user SET
          nick = '$nick',
          name = '$name',
          email = '$email',
          homepage = '$homepage'
          WHERE userID = $userID";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    print "User modified<p>\n";

    // close session
    mysql_close($link);
  }

  function list_fotos($userID)
  {
    // Connecting and selecting database
    $link = mysql_connect("localhost", "anonymous")
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    $query = "SELECT fotoID,beschrijving
          FROM foto WHERE userID = $userID
          ORDER BY fotoID";

    $result = mysql_query($query)
    or die("Query '$query' failed");

    print "<input type=\"hidden\" name=\"userID\" value=\"$userID\">\n";

    // Printing results in HTML form language
    print "<select size=\"6\" name=\"fotoID\">\n";
    while ($line = mysql_fetch_row($result)) {
    print "<option value=\"$line[0]\">$line[1]</option>\n";
    }
    print "</select>\n";

    // close result
    mysql_free_result($result);

    // close session
    mysql_close($link);
  }

  function print_foto($fotoID, $userID)
  {
    if ($fotoID)
    {
    // Connecting, selecting database
    $link = mysql_connect("localhost", "anonymous")
      or die("Could not connect to MySQL");
    mysql_select_db(real_database)
      or die("Could not select database");

    // get the paper table
    $query = "SELECT fotoID,beschrijving,nemer,datum,path
            FROM foto WHERE fotoID = $fotoID";
    $result = mysql_query($query)
      or die("Query '$query' failed");

    $line = mysql_fetch_row($result);
    }

    if ($fotoID)
    print "<input type=\"hidden\" name=\"fotoID\" value=\"$fotoID\">\n";
    if ($userID)
    print "<input type=\"hidden\" name=\"userID\" value=\"$userID\">\n";

    print "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">\n";

    if ($fotoID)
    {
    print "\t<tr>\n\t\t<td align=middle colspan=\"2\">\n";
    print "\t\t\t[img]\"fotos_thumbnails/$line[4]\">\n";
    print[/img]\n\t</tr>\n";
    }
    else
    {
    print "\t<tr>\n";
    print "\t\t<td><b>Foto: </b></td>\n";
    print "\t\t<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\">\n";
    print "\t\t<td><input type=\"file\" name=\"imagefile\" accept=\"image/jpeg,jpg\">\n";
    print "\t</tr>\n";
    }

    print "\t<tr>\n";
    print "\t\t<td><b>Beschrijving: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"beschrijving\" value=\"$line[1]\"></td>\n";
    print "\t</tr>\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Nemer: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"nemer\" value=\"$line[2]\"></td>\n";
    print "\t</tr>\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Datum: </b></td>\n";
    print "\t\t<td><input type=\"text\" name=\"datum\" value=\"$line[3]\"></td>\n";
    print "\t</tr>\n";
    print "</table>\n";

    if ($fotoID)
    {
    // free result
    mysql_free_result($result);

    //close session
    mysql_close($link);
    }
  }

  function add_foto($userID,$beschrijving,$nemer,$datum,$imagefile)
  {
    include "login.php";

    // Connecting, selecting database
    $link = mysql_connect("localhost", real_username, real_password)
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    // figure out a nice filename
    $query = "SELECT nick
          FROM user
          WHERE userID = $userID";
    $result1 = mysql_query($query)
    or die("Query '$query' failed");
    $line1 = mysql_fetch_row($result1);
    $query = "SELECT count(*)
          FROM foto
          WHERE userID = $userID";
    $result2 = mysql_query($query)
    or die("Query '$query' failed");
    $line2 = mysql_fetch_row($result2);
    $line2[0]++;
    $filename = "$line1[0]_$line2[0].jpg";
    mysql_free_result($result1);
    mysql_free_result($result2);

    // write the image data
    move_uploaded_file($imagefile, "fotos/$filename");

    // now, create a thumbnail
    $size = getimagesize("fotos/$filename");
    $width = $size[0];
    $height = $size[1];
    if ($width > $height)
    {
    $height = $height * 100 / $width;
    $width = 100;
    }
    else
    {
    $width = $width * 100 / $height;
    $height = 100;
    }
    system("convert -size $widthx$height fotos/$filename fotos_thumbnails/$filename");

    // files exist, now add it to the database
    $query = "INSERT INTO foto
          VALUES(null,$userID,'$beschrijving','$nemer','$filename','$datum')";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    print "Foto added<p>\n";

    mysql_close($link);
  }

  function modify_foto($fotoID,$beschrijving,$nemer,$datum)
  {
    include "login.php";

    // Connecting and selecting database
    $link = mysql_connect("localhost", real_username, real_password)
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    $query = "UPDATE foto SET
          beschrijving = '$beschrijving',
          nemer = '$nemer',
          datum = '$datum'
          WHERE fotoID = $fotoID";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    print "User modified<p>\n";

    // close session
    mysql_close($link);
  }

  function remove_foto($fotoID)
  {
    include "login.php";

    // Connecting and selecting database
    $link = mysql_connect("localhost", real_username, real_password)
    or die("Could not connect to MySQL");
    mysql_select_db(real_database)
    or die("Could not select database");

    // selecteer foto's van die user en remove
    $query = "SELECT path
          FROM foto
          WHERE fotoID = $fotoID";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    while ($line = mysql_fetch_row($result))
    {
    // remove the fotos in $path
    unlink("fotos_thumbnails/$path");
    unlink("fotos/$path");
    }
    mysql_free_result($result);

    $query = "DELETE FROM foto
          WHERE fotoID = $fotoID";
    $result = mysql_query($query)
    or die("Query '$query' failed");
    print "Foto removed<p>\n";

    // close session
    mysql_close($link);
  }

  if (!$password)
    $password = $HTTP_COOKIE_VARS["password"];
  if (!$username)
    $username = $HTTP_COOKIE_VARS["username"];

  if (!strcmp($action, "uitloggen"))
  {
    setcookie("username", "");
    $username = "";
    setcookie("password", "");
    $password = "";
  }

  if (strcmp($password, real_password) ||
    strcmp($username, real_username))
  {
    page_header("Admin interface log-in");

    // let the user log in
    print "<form action=\"admin.php\" method=\"post\">\n";

    print "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\">\n";
    print "\t<tr>\n";
    print "\t\t<td><b>Login: </b></td>\n";
    print "\t\t<td><input name=\"username\" type=\"text\" size=20></td>\n";
    print "\t</tr>\n";

    print "\t<tr>\n";
    print "\t\t<td><b>Password: </b></td>\n";
    print "\t\t<td><input name=\"password\" type=\"password\" size=20></td>\n";    print "\t</tr>\n";

    print "\t<tr>\n";
    print "\t\t<td colspan=\"2\"><input type=\"submit\" value=\"Login\"></td>\n";
    print "\t</tr>\n";
    print "</table>\n";

    print "</form>\n";
  }
  else
  {
    // set cookies
    setcookie("username", $username);
    setcookie("password", $password);

    page_header("Admin interface");

    print "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"50%\">\n";
    print "\t<tr>\n";
    print "\t\t<td>\n";
    print "- <a href=\"admin.php?action=useradd\">User toevoegen</a><br>\n";
    print "- <a href=\"admin.php?action=usermod\">User wijzigen</a><br>\n";
    print "- <a href=\"admin.php?action=userdel\">User verwijderen</a>\n";
    print "<p>\n";
    print "- <a href=\"admin.php?action=fotoadd\">Foto toevoegen</a><br>\n";
    print "- <a href=\"admin.php?action=fotomod\">Foto wijzigen</a><br>\n";
    print "- <a href=\"admin.php?action=fotodel\">Foto verwijderen</a>\n";
    print "<p>\n";
    print "- <a href=\"admin.php?action=uitloggen\">Uitloggen</a>\n";
    print "\t\t</td>\n";
    print "\t</tr>\n";
    print "</table>\n<p>\n";

    if (!strcmp($action, "useradd"))
    {
    //print "User toevoegen\n";

    if ($nickname)
    {
      add_user($nickname,$naam,$email,$homepage);
    }

    print "<form action=\"admin.php?action=useradd\" method=\"post\">\n";
    print_user(0);
    print "<p>\n<input type=\"submit\" value=\"Voeg user toe\">\n";
    print "</form>\n";
    }
    else if (!strcmp($action, "usermod"))
    {
    //print "User wijzigen\n";

    if ($userID)
    {
      if ($nickname)
      {
        modify_user($userID,$nickname,$naam,$email,$homepage);
      }

      print "<form action=\"admin.php?action=usermod\" method=\"post\">\n";
      print_user($userID);
      print "<p>\n<input type=\"submit\" value=\"wijzig gebruiker\">\n";
      print "</form>\n";
    }
    else
    {
      print "<form action=\"admin.php?action=usermod\" method=\"post\">\n";
      list_users();
      print "<p>\n<input type=\"submit\" value=\"Wijzig user\">\n";
      print "</form>\n";
    }
    }
    else if (!strcmp($action, "userdel"))
    {
    //print "User verwijderen\n";

    if ($userID)
    {
      remove_user($userID);
    }

    print "<form action=\"admin.php?action=userdel\" method=\"post\">\n";
    list_users();
    print "<p>\n<input type=\"submit\" value=\"Verwijder user\">\n";
    print "</form>\n";
    }
    else if (!strcmp($action, "fotoadd"))
    {
    //print "Foto toevoegen\n";

    if ($userID)
    {
      if ($beschrijving)
      {
        add_foto($userID,$beschrijving,$nemer,$datum,$imagefile);
      }

      print "<form enctype=\"multipart/form-data\" action=\"admin.php?action=fotoadd\" method=\"post\">\n";
      print_foto(0,$userID);
      print "<p>\n<input type=\"submit\" value=\"Voeg foto toe\">\n";
      print "</form>\n";
    }
    else
    {
      print "<form action=\"admin.php?action=fotoadd\" method=\"post\">\n";
      list_users();
      print "<p>\n<input type=\"submit\" value=\"Selecteer user\">\n";
      print "</form>";
    }
    }
    else if (!strcmp($action, "fotomod"))
    {
    //print "Foto wijzigen\n";

    if ($fotoID)
    {
      if ($beschrijving)
      {
        modify_foto($fotoID,$beschrijving,$nemer,$datum);
      }

      print "<form action=\"admin.php?action=fotomod\" method=\"post\">\n";
      print_foto($fotoID,0);
      print "<p>\n<input type=\"submit\" value=\"Wijzig foto\">\n";
      print "</form>";
    }
    else if ($userID)
    {
      print "<form action=\"admin.php?action=fotomod\" method=\"post\">\n";
      list_fotos($userID);
      print "<p>\n<input type=\"submit\" value=\"Selecteer foto\">\n";
      print "</form>";
    }
    else
    {
      print "<form action=\"admin.php?action=fotomod\" method=\"post\">\n";
      list_users();
      print "<p>\n<input type=\"submit\" value=\"Selecteer user\">\n";
      print "</form>";
    }
    }
    else if (!strcmp($action, "fotodel"))
    {
    //print "Foto verwijderen\n";

    if ($fotoID)
    {
      remove_foto($fotoID);
    }
    if ($userID)
    {
      print "<form action=\"admin.php?action=fotodel\" method=\"post\">\n";
      list_fotos($userID);
      print "<p>\n<input type=\"submit\" value=\"Verwijder foto\">\n";
      print "</form>";
    }
    else
    {
      print "<form action=\"admin.php?action=fotodel\" method=\"post\">\n";
      list_users();
      print "<p>\n<input type=\"submit\" value=\"Selecteer user\">\n";
      print "</form>";
    }
    }
  }

  page_footer();
?>
[rbultje@gizmo dutch]$

login.php ziet er zo uit:
code:
1
2
3
4
5
<?php
define("real_password", "<password>");
define("real_username", "<username>");
define("real_database", "<database>");
?>

Misschien dat iemand anders er ook nog eens ideetjes uit kan halen. :).

D'r is vast nog heel veel aan te verbeteren (encrypted passwords, meer opties, fancy layout (plaatjes, tabellen, ...), iets zinnigers dan 'convert' (van ImageMagick) gebruiken om de plaatjes te resizen, fatsoenlijke error handling)... Maar op zich werkt het redelijk goed. :Y).

Acties:
  • 0 Henk 'm!

  • CmdrKeen
  • Registratie: Augustus 2000
  • Laatst online: 26-09 16:28

CmdrKeen

Krentenboltosti

Mijn code voor een ASP gastenboek - hoop dat iemand er wat aan heeft.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<% @Language = "VBScript" %>
<% Option Explicit %>
<%

' Martin Huijgen www.huijgen.com
' Voor gebruik is een Access 97> database nodig met vijf tabellen:
' EntryID (Autonummering, Primaire sleutel); naam (tekst); email (tekst); site (tekst); tekst (memo); en datum (datum (maakt niet uit welke)).
' Account IUSR_[jouw-computer-naam-hier] moet lees- en schrijfrechten hebben.

%>

<HTML>

<%
' Verbinding maken met database

Dim rs, Conn, nw, naam, SQLstmt, email, site, Datum, tekst, LenTekst, kuizer, kuizetekst

Set rs = Server.CreateObject ("ADODB.Recordset")
Set Conn = Server.CreateObject ("ADODB.Connection")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("gastenboek.mdb")

' Tsjekke of de lezer op de new-entry link geklikt heeft
nw = Request.QueryString("nw")

' Tsjekke of dit een postback van het form is
naam = Request.Form("naam")

' Als dit een postback is, dan de db updaten
IF naam <> "" THEN
    email = Request.Form("email")
    site = Request.Form("site")
    tekst = Request.Form("tekst")

    ' Zorgen datter geen HTML in de entry zit door < en > te vervangen door [ en ]
    LenTekst = LEN(tekst)
    IF LenTekst > 999 THEN
        tekst = LEFT(tekst,999)
        LenTekst = 999
    END IF
    Dim newtxt(999)
    FOR kuizer = 1 to LenTekst
        newtxt(kuizer)=mid(tekst,kuizer,1)
        if newtxt(kuizer)="<" THEN newtxt(kuizer)="["
        if newtxt(kuizer)=">" THEN newtxt(kuizer)="]"
        kuizetekst = kuizetekst & newtxt(kuizer)
    NEXT
    Datum = MediumDate(Date)

    SQLstmt = "INSERT INTO entries (naam, email, site, tekst, datum) VALUES ('" & naam & "', '" & email & "', '" & site & "', '" & kuizetekst & "', #" & datum & "#)"
    Conn.Execute(SQLstmt)

END IF

%>

<H1>Gastenboek</H1>
<% IF nw="" THEN %>
    <A HREF = gastenboek.asp?nw=jah>Schrijf een verhaaltje in mn gastenboek</A><BR>
<% END IF

' Formulier
IF nw = "jah" THEN
    %>
    <FORM METHOD="POST" ACTION="gastenboek.asp">
    <TABLE WIDTH = 200 BORDER = 0>
        <TR>
            <TD>
                Naam:
            </TD>
            <TD>
                <INPUT TYPE="text" NAME="naam" SIZE="30">
            </TD>
        </TR>
        <TR>
            <TD>
                Email:
            </TD>
            <TD>
                <INPUT TYPE="text" NAME="email" SIZE="30">
            </TD>
        </TR>
        <TR>
            <TD>
                Site:
            </TD>
            <TD>
                <INPUT TYPE="text" NAME="site" SIZE="30">
            </TD>
        </TR>
        <TR>
            <TD COLSPAN = 2>
                <TEXTAREA NAME="tekst" ROWS=6 COLS=30></TEXTAREA>
            </TD>
        </TR>
        <TR>
            <TD>
                <FONT SIZE = 1>
                    Gebruik geen HTML-tags..
                </FONT>
            </TD>
            <TD ALIGN = Right>
                <INPUT TYPE="submit" Name = "submit" Value="Ok!">
            </TD>
        </TR>
    </TABLE>
    </FORM>
    <%
END IF

' Inhoud van de db op het scherm dumpen
%><P><%
SQLstmt = "SELECT * FROM entries ORDER BY datum Desc"
rs.OPEN SQLstmt, Conn
DO WHILE NOT rs.EOF
    naam = rs("naam")
    IF naam = "" THEN naam = "Anoniem"
    naam = naam & "<BR>"
    email = rs("email")
    IF email<>"" THEN email = email & "<BR>"
    site = rs("site")
    IF site<>"" THEN site = site & "<BR>"
    datum = rs("datum")
    tekst = rs("tekst")
    %>
    <B><%=naam%></B>
    <%=email%>
    <%=site%>
    <%=datum%>
    <BR>----------------------<BR>
    <% tekst=Replace(tekst,vbCrLf,"<br>")%>
    <%=tekst%>
    <HR>
    <%
    rs.MOVENEXT
LOOP
%>

<%
rs.close
set rs=nothing
set Conn=nothing
%>

<%
Function MediumDate (str)
    Dim aDay
    Dim aMonth
    Dim aYear

    aDay = Day(str)
    aMonth = MonthName(Month(str),True)

    IF aMonth = "mrt" THEN
        aMonth = "mar"
    END IF
    IF aMonth = "mei" THEN
        aMonth = "may"
    END IF
    IF aMonth = "okt" THEN
        aMonth = "oct"
    END IF


    aYear = Year(str)

    MediumDate = aDay & "-" & aMonth & "-" & aYear
End Function
%>

Bloed, zweet & koffie


Acties:
  • 0 Henk 'm!

  • Tomatoman
  • Registratie: November 2000
  • Laatst online: 20:12

Tomatoman

Fulltime prutser

Taal: Delphi
Doel: screenshot maken van de hele desktop of van één van de aangesloten monitors.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
interface

{ retrieve extents of the entire desktop - all monitors together in their
  relative positions }
procedure GetDesktopScreenshot(Image: TImage);

{ retrieve the desktop extents of the indicated monitor }
procedure GetMonitorScreenshot(Image: TImage; Monitor: TMonitor);

implementation

procedure GetDesktopScreenshot(Image: TImage);
begin
  GetMonitorScreenshot(Image, nil);
end;

procedure GetMonitorScreenshot(Image: TImage; Monitor: TMonitor);
var
  Canvas: TCanvas;
  SrcRect, DestRect: TRect;
begin
  if Monitor = nil then
    {retrieve extents of the entire desktop - all monitors together in their
     relative positions}
    with Screen do
    begin
    SrcRect := Rect(DesktopLeft, DesktopTop,
                DesktopLeft + DesktopWidth, DesktopTop + DesktopHeight);
    DestRect := Rect(0, 0, DesktopWidth, DesktopHeight);
    end
  else
    {retrieve the desktop extents of the indicated monitor}
    with Monitor do
    begin
    SrcRect := Rect(Left, Top, Left + Width, Top + Height);
    DestRect := Rect(0, 0, Width, Height);
    end;

  Canvas := TCanvas.Create;
  try
    {clear current image}
    Image.Picture.Bitmap.Width := 0;
    Image.Picture.Bitmap.Height := 0;

    Canvas.Handle := GetDC(0);    // retrieve device context of desktop
    Image.Picture.Bitmap.Width := DestRect.Right;
    Image.Picture.Bitmap.Height := DestRect.Bottom;
    Image.Width := DestRect.Right;
    Image.Height := DestRect.Bottom;
    Image.Canvas.CopyMode := srcCopy;
    {paint desktop on canvas of Image}
    Image.Canvas.CopyRect(DestRect, Canvas, SrcRect);
  finally
    Canvas.Free;
  end;
end;

Een goede grap mag vrienden kosten.


Acties:
  • 0 Henk 'm!

  • me1299
  • Registratie: Maart 2000
  • Laatst online: 16:19

me1299

$ondertitel

Taal: PHP

Doel: Handige kleine data conversie functie :Y)
PHP:
1
<?function dmj($datetime) {    return substr($datetime, 8, 2) . "-" . substr($datetime, 5, 2) . "-" . substr($datetime, 0, 4);}function hm($datetime) {    return substr($datetime, 11, 5);}function jmd($date) {    list($day, $month, $year) = split( '[/.-]', $date );    if(checkdate($month, $day, $year)) {        return date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));    }    else {         return "0000-00-00"; }}?>

Het maakt eigenlijk niet uit wat je bewuste geest doet, omdat je onderbewuste automatisch precies dat doet wat het moet doen


Acties:
  • 0 Henk 'm!

  • Vampier
  • Registratie: Februari 2001
  • Laatst online: 20-04-2015

Vampier

poke-1,170

CSV bestand (punt komma gescheiden) naar Table (asp/jscript)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function ReadCSV(fileName){

var i=0
var InString
var SplitStringArray

  var objFSO         = Server.CreateObject("Scripting.FileSystemObject");
  objTextStream  = objFSO.OpenTextFile(fileName,1,0);

Response.write ('<table border="1">')
while (objTextStream.AtEndOfStream!=true)
  {
    InString=objTextStream.readLine()
    SplitStringArray = InString.split(';');
    Response.write ('<tr>')
    for (i=0; i<SplitStringArray.length; i++ )
    {
        Response.write ('<td>'+SplitStringArray[i]+'</td>')
    }
    Response.write ('</tr>')
  }

objTextStream.Close()
objFSO=null
Response.write ('</table>')

}

Acties:
  • 0 Henk 'm!

  • Baxlash
  • Registratie: Juni 2000
  • Niet online

Baxlash

Its a boy Genius!

Taal: PHP
Doel: SMS sturen
PHP:
1
<?//$bericht = "test";//$nummer = "0031612345678";//* Session - Get the smsid! *\\$post = "GET http://www5.cp1.campoints.net/CMPT/---guest---/001/105/0/cy=XX,La=TR,option=/DE/001//user/menu.php?page=sms HTTP/1.0\nHost: www5.cp1.campoints.net\n\n";$remote = fsockopen("www5.cp1.campoints.net", 80, &amp;$errno, &amp;$errstr, 30);if (!$remote) die("Host not available.");fputs($remote, $post);while ((!feof($remote)) OR (!$smsid))     {     $getreply = fgets($remote,120);    if (eregi("smsID",$getreply)) $smsid = $getreply;    }fclose($remote);$smsid = trim(str_replace(">","",str_replace("'","",str_replace('<form method="post" action="menu.php?page=sms"><input type=hidden name=smsID value=','',$smsid))));//* Session - Send the sms! *\\$content = "what=SEND_SMS&amp;smsID=$smsid&amp;smsBody=".urlencode($bericht)."&amp;smsNummer=".$nummer."&amp;Submit=absenden";$content_length = strlen($content);$post ="POST http://www5.cp1.campoints.net/CMPT/---guest---/001/105/0/cy=XX,La=TR,option=/DE/001//user/menu.php?page=sms HTTP/1.0\nContent-Type: application/x-www-form-urlencoded\nHost: www5.cp1.campoints.net\nContent-Length: $content_length\n\n$content";$remote = fsockopen("www5.cp1.campoints.net", 80, &amp;$errno, &amp;$errstr, 30);if (!$remote) die("Host not available.");fputs($remote, $post);while (!feof($remote))     {     if (eregi("Die SMS wurde erfolgreich versand!",fgets($remote,120))) $smssend = true;    }fclose($remote);if ($smssend == true) { echo "Sms is verstuurd."; } else { echo "Fout bij het versturen van sms!"; }?>

Acties:
  • 0 Henk 'm!

  • Choller
  • Registratie: Juli 2001
  • Laatst online: 22-05-2024
Op maandag 06 mei 2002 17:12 schreef rolandketel het volgende:
Taal: PHP
Doel: SMS sturen
[phpcode[/php]
|:(

Nevermind, it works.

Acties:
  • 0 Henk 'm!

  • Baxlash
  • Registratie: Juni 2000
  • Niet online

Baxlash

Its a boy Genius!

Op maandag 06 mei 2002 17:53 schreef Choller het volgende:

[..]

Fout bij het versturen van sms! ......
Hier werkt het ok, dus probeer zelf ook nog eens wat, zoek wat het kan zijn :D

Acties:
  • 0 Henk 'm!

  • smaij
  • Registratie: November 2000
  • Laatst online: 28-09 23:03
Op maandag 06 mei 2002 17:55 schreef rolandketel het volgende:

[..]

Hier werkt het ok, dus probeer zelf ook nog eens wat, zoek wat het kan zijn :D
Bij mij werkt het ook.. en ik weet zeker dat heeeel veel mensen hiervan gebruik gaan maken :)

Acties:
  • 0 Henk 'm!

  • martinvw
  • Registratie: Februari 2002
  • Laatst online: 20-08 20:35
FF een vraagje zijn er mensen die dat sms script nog steeds gebuiken want bij mij lijkt het niet meer* het werken. Ik krijg telkens een:
code:
1
Fatal error: Maximum execution time of 15 seconds exceeded in /www/wwworg/***/html/ls/smsen.php on line 12

en dat is de regel waarin de socket wordt uitgelezen:
PHP:
1
<?..knip..while ((!feof($remote)) OR (!$smsid))    {     $getreply = fgets($remote,120); //dit is de probleem regel    if (eregi("smsID",$getreply)) $smsid = $getreply;    }fclose($remote);..knip..?>

* hij heeft dus wel enige tijd succesvol gewerkt.

Acties:
  • 0 Henk 'm!

  • Limhes
  • Registratie: Oktober 2001
  • Laatst online: 28-09 17:41
Op woensdag 24 april 2002 20:50 schreef Orphix het volgende:
Taal: C#
Doel: Het genereren van een typische MD5 Hash van een gegeven string. De standaard hash functie in .NET retourneert byte-waardes. Deze functie vertaalt dit naar een leesbare (ASCII) string zoals vaak de bedoeling is (wachtwoorden, msn, etc).
code:
1
2
3
4
5
6
7
8
9
10
11
12
protected string HashMD5(string input)
{
    byte[] result = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(TextEncoding.GetBytes(input));
    string output = "";
                              
    for (int i = 0; i < result.Length; i++) 
    {           
        // convert from hexa-decimal to character
        output += (result[i]).ToString( "x2" );
    }
    return output;
}
kan makkelijker:
code:
1
2
3
using System.Web.Security;
...
String sFromMD5 = FormsAuthentication.HashPasswordForStoringInConfigFile(sToMD5, "md5");

Acties:
  • 0 Henk 'm!

  • whoami
  • Registratie: December 2000
  • Laatst online: 22:56
toepassing = deze berekening wordt veel gebruikt in encryptie algoritmes. Natuurlijk is int64 veel te klein om een leuke waarde voor encryptie in te stoppen, maar het skelet van de code blijft gelijk als je hier je eigen bignumber-class voor gebruikt. Je hebt dan wel een algoritme nodig dat efficient de mod van een getal van je eigen bignumber type uitrekend, en om dat te doen staat hieronder een bignumber-mod algoritme.
ach leuk, dit zien wij nu toevallig in wiskunde ...
verdomd niet eenvoudig. 'k Weet wel dat twee belgen een nieuwe encryptietechniek Rijndaal (ESA) hebben die gebaseerd is daarop en die beter is dan de vorige (RSA)

https://fgheysels.github.io/


Acties:
  • 0 Henk 'm!

  • Juup
  • Registratie: Februari 2000
  • Niet online
Op zaterdag 25 mei 2002 15:50 schreef whoami het volgende:
'k Weet wel dat twee belgen een nieuwe encryptietechniek Rijndaal (ESA) hebben die gebaseerd is daarop en die beter is dan de vorige (RSA)
Rijndael met een 'e'.

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.


Acties:
  • 0 Henk 'm!

  • Feyd-Rautha
  • Registratie: November 2001
  • Laatst online: 02-08 23:34
als "project" voor school heb ik eens een e-commerce site moeten maken met winkelkarretje, banners, ... alles erop en eraan. Deze kun je namelijk bekijken op volgende URL:

user.domaindlx.com/FlandersFoodDelivery/index.asp

Zelf ben ik trots op volgende code om artikelen toe te voegen in de winkelkar in ASP:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
for each Item in Request.Form       ' alle aantalvakjes van het form ophalen
    itmAantal = server.HTMLEncode(Request.Form(Item))
            
                        
    if itmAantal <> "" and isnumeric(itmAantal) and _
        itmAantal > "0" and itmAantal <> "Toevoegen" then
            
        tabel = split(Item, "_")   ' alle onderdelen van de naam scheiden
                                    ' tabel(0) is de tekst 'ATL'
        categorie = tabel(1)        
        product   = tabel(2)
        aantal    = cdbl(itmAantal)
            
          ' we gebruiken een dictionary om alle goederen op te slaan in de winkelkar.  
        ' De dictionary gebruikt een index (key) + een waarde
        ' 
        ' Key = SoortID + ProductID
        ' Waarde = aantal
        
        sleutel = categorie & "_" & product
        waarde  = aantal
            
        
        if karretje.Exists(sleutel) then ' als dit product reeds in het karretje zit,
                                        ' tel dan het aantal erbij op
            karretje(sleutel)  = karretje(sleutel) + cdbl(waarde )
        else
            karretje.Add sleutel, cdbl(waarde)      ' anders, voeg het product toe
        end if  
            
            
            
    end if  
next

... zelf met gebruik te maken van analytische codes 8-)

I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. Where the fear has gone there will be nothing. Only I will remain.


Acties:
  • 0 Henk 'm!

  • wasigh
  • Registratie: Januari 2001
  • Niet online

wasigh

wasigh.blogspot.com

Topicstarter
Bekijk ook even www.codebase.nl :)

Acties:
  • 0 Henk 'm!

Verwijderd

*schopje*
Op maandag 06 mei 2002 17:12 schreef Baxlash het volgende:
Taal: PHP
Doel: SMS sturen
Ik zie hetvolgende stukje code al aankomen waarbij de sms code ietsje veranderd is... >:)
PHP:
1
<?while (X != 1000) {    <de sms code hier> X++;}?>

Acties:
  • 0 Henk 'm!

  • HGM
  • Registratie: April 2000
  • Niet online

HGM

Op zondag 26 mei 2002 12:27 schreef wasigh het volgende:
Bekijk ook even www.codebase.nl :)
;)

Acties:
  • 0 Henk 'm!

  • ACM
  • Registratie: Januari 2000
  • Niet online

ACM

Software Architect

Werkt hier

right :)
Pagina: 1 2 Laatste

Dit topic is gesloten.