PHP-Codeschnippsel & Anfragen

  • Sollten Anfragen zu PHP geben oder einfache Fragen bitte hier Posten.
    Oder einfache und nützliche Codeschnippsel Posten, sollte dieser Bereich falsch sein bitte Verschieben.
    Ich fang mal an:


    Das ist eine kleine Security Aufentziehrung. Es checkt, ob der User Regisitert ist, sowie ob die Passwörter zustimmen.
    Es ist sehr Hilfsreich, wenn man einen Login per Include macht.

  • Vor kurzem hatte ich einen kleinen PHP-Code gefunden, mit dem man zufällig Bilder aus einem bestimmten Verzeichnis aufrufen lassen kann.
    Hast du sowas parat?


    Die Bilder sollten dann je Seitenaufruf wechseln.
    So ein Script hatte ich mal gefunden, doch durch die letzte Formatierung meines Lappy's habe ich diesen Code wieder verloren.

  • Ich wollte einmal fragen, ob jemand eine art Sigcreator code hat.
    Würde mich gern interessieren :p




    Vor kurzem hatte ich einen kleinen PHP-Code gefunden, mit dem man zufällig Bilder aus einem bestimmten Verzeichnis aufrufen lassen kann.
    Hast du sowas parat?


    Die Bilder sollten dann je Seitenaufruf wechseln.
    So ein Script hatte ich mal gefunden, doch durch die letzte Formatierung meines Lappy's habe ich diesen Code wieder verloren.


    Sowas eventuell?

    PHP
    <?php
    mt_srand((double)microtime() * 1000000); //In Minuten
    $bildnummer = mt_rand(1,5); //Wie viele Bilder (1-5)
    echo "<img src=\"bild".$bildnummer.".gif\">"; //So ruft er die auf
    ?>
  • HTML
    <html>
    <head>
    </head>
    <body>
    <form action="processor.php" method=POST>
    <input type=text name=idhtml size="25" value="Schreibe deinen Namen hier hinein"><br>
    <input type="submit" value="Bild erstellen">
    </form>
    </body>
    </html>


    das script nennste einfach index.html...
    funktioniert nur unter der vorraussetzung,dass du das obige script "processor.php" nennst und "DeinName ist MeinName!" (ink. der anführungszeichen) mit $_POST['idhtml'] ersetzt.


    ps: untested

  • danke :D
    Aber weisst du wie ich die Schrift nach unten hinsetze?
    Und gegebenfalls eine andere Schrift wähle?


    Ist es auch noch möglich gedownloadete Fonts einzubeziehen?

  • um die position des textes zu ändern musst du einfach bei

    Code
    ImageString($img, 3, $image_center_x, $image_center_y, $text, $white);

    mit dem 3. und 4. Parameter rumspielen (hängt von der größe des hintergrundbildes ab).


    Gedownloadete Fonts bekommste nur auf kompliziertem Umweg in das Bild.

  • habe eigentlich auch nicht wirklich vor mich mit HTML/PHP zu beschäftigen.
    Darum komm ich damit nicht klar :p
    // nach einigen versuchen bin ich nicht weiter gekommen :(

    Einmal editiert, zuletzt von -SOAD- ()

  • Zitat

    Achtung! Die letzte Antwort auf dieses Thema liegt mehr als 1 081 Tage
    zurück. Das Thema ist womöglich bereits veraltet. Bitte erstellen Sie ggf. ein neues Thema.

    Problem officer?




    Kleiner Ausschnitt meiner Core.class.php:



    Die Konstanten müssen halt ggf. definiert werden.


    Aufruf wäre z. B. so:


    PHP
    // imports core
    require_once 'Core.class.php';
    // get database object
    $dbh = Core::getDB();
    // ...
  • Moin,


    kleiner Tipp für Variablen in PHP:



    PHP
    // Möglichkeit 1 (finde ich übersichtlicher)
    $i = 12;
    ${'variable'. $i} = 'hey';
    // Variable: $variable12 = hey
     
    // Möglichkeit 2
    $varName = 'variablenName';
    $$varName = 'okey :P';
    // Variable: $variablenName = okey :P


    So könnt ihr Variablennamen aus Variablen bilden. *thumbup*

  • PHP
    $Cars = array("602" => "Alpha","545" => "Hustler","496" => "Blista Compact","517" => "Majestic","401" => "Bravura","410" => "Manana","518" => "Buccaneer","600" => "Picador","527" => "Cadrona","436" => "Previon","589" => "Club","580" => "Stafford","419" => "Esperanto","439" => "Stallion","533" => "Feltzer","549" => "Tampa","526" => "Fortune","491" => "Virgo","474" => "Hermes","445" => "Admiral","467" => "Oceanic","604" => "Glendale Damaged","426" => "Premier","507" => "Elegant","547" => "Primo","585" => "Emperor","405" => "Sentinel","587" => "Euros","409" => "Stretch","466" => "Glendale","550" => "Sunrise","492" => "Greenwood","566" => "Tahoma","546" => "Intruder","540" => "Vincent","551" => "Merit","421" => "Washington","516" => "Nebula","529" => "Willard","592" => "Andromada","553" => "Nevada","577" => "AT-400","488" => "News Chopper","511" => "Beagle","497" => "Police Maverick","548" => "Cargobob","563" => "Raindance","512" => "Cropduster","476" => "Rustler","593" => "Dodo","447" => "Seasparrow","425" => "Hunter","519" => "Shamal","520" => "Hydra","460" => "Skimmer","417" => "Leviathan","469" => "Sparrow","487" => "Maverick","513" => "Stuntplane","581" => "BF-400","510" => "Mountain Bike","509" => "Bike","522" => "NRG-500","481" => "BMX","461" => "PCJ-600","462" => "Faggio","448" => "Pizzaboy","521" => "FCR-900","468" => "Sanchez","463" => "Freeway","586" => "Wayfarer","472" => "Coastguard","473" => "Dinghy","493" => "Jetmax","595" => "Launch","484" => "Marquis","430" => "Predator","453" => "Reefer","452" => "Speeder","446" => "Squalo","454" => "Tropic","485" => "Baggage","552" => "Utility Van","431" => "Bus","438" => "Cabbie","437" => "Coach","574" => "Sweeper","420" => "Taxi","525" => "Towtruck","408" => "Trashmaster","416" => "Ambulance","596" => "Police LS","433" => "Barracks","597" => "Police SF","427" => "Enforcer","599" => "Police Ranger","490" => "FBI Rancher","432" => "Rhino","528" => "FBI Truck","601" => "S.W.A.T.","407" => "Fire Truck","428" => "Securicar","544" => "Fire Truck Ladder","523" => "HPV1000","470" => "Patriot","598" => "Police LV","499" => "Benson","588" => "Hotdog","609" => "Boxville Mission","403" => "Linerunner","498" => "Boxville","514" => "Tanker","524" => "Cement Truck","423" => "Mr. Whoopee","532" => "Combine Harvester","414" => "Mule","578" => "DFT-30","443" => "Packer","486" => "Dozer","515" => "Roadtrain","406" => "Dumper","531" => "Tractor","573" => "Dune","456" => "Yankee","455" => "Flatbed","459" => "Berkley's RC Van","543" => "Sadler","422" => "Bobcat","583" => "Tug","482" => "Burrito","478" => "Walton","605" => "Sadler Damaged","554" => "Yosemite","530" => "Forklift","418" => "Moonbeam","572" => "Mower","582" => "Newsvan","413" => "Pony","440" => "Rumpo","536" => "Blade","575" => "Broadway","534" => "Remington","567" => "Savanna","535" => "Slamvan","576" => "Tornado","412" => "Voodoo","402" => "Buffalo","542" => "Clover","603" => "Phoenix","475" => "Sabre","449" => "Tram","537" => "Freight","538" => "Streak","441" => "RC Bandit","464" => "RC Baron","501" => "RC Goblin","465" => "RC Raider","564" => "RC Tiger","568" => "Bandito","557" => "Monster 3","424" => "BF Injection","471" => "Quadbike","504" => "Bloodring Banger","495" => "Sandking","457" => "Caddy","539" => "Vortex","483" => "Camper","508" => "Journey","571" => "Kart","500" => "Mesa","444" => "Monster 1","556" => "Monster 2","429" => "Banshee","411" => "Infernus","541" => "Bullet","559" => "Jester","415" => "Cheetah","561" => "Stratum","480" => "Comet","560" => "Sultan","562" => "Elegy","506" => "Super GT","565" => "Flash","451" => "Turismo","434" => "Hotknife","558" => "Uranus","494" => "Hotring Racer","555" => "Windsor","502" => "Hotring Racer 3","477" => "ZR-350","503" => "Hotring Racer 2","579" => "Huntley","400" => "Landstalker","404" => "Perennial","489" => "Rancher","505" => "Rancher Lure","479" => "Regina","442" => "Romero","458" => "Solair","590" => "Box Freight","569" => "Freight Train Flatbed","594" => "RC Cam");


    Array mit allen IDs zugeordnet an den Autonamen

  • Habe wenig gelernt kam das hier zu Stande vielleicht brauch es ja jemand zur an Anmerkung ich bin noch Anfänger.


    Mit dem Script kann man sachen von Servern öffnen und editieren vereinfacht!




  • Meine geliebte dump Funktion, am besten bei OOP Projekten direkt statisch in den Core mit rein - Core::dump($var)
    Super einfach, aber ziemlich praktisch, spart mir jedenfalls das ewige <pre></pre>

    PHP
    function dump($var) {
    echo '<pre>';
    var_dump($var);
    echo '</pre>';
    }



    vs


    Einmal editiert, zuletzt von Lars ()

  • Hier eine Funktion, um anhand eines Offsets die Zeilennummer innerhalb eines Strings zu bestimmten.
    Vielleicht kann sie jemand gebrauchen.


    PHP
    function getLineFromOffset($string, $offset) {
    $lineNo = 1 + @substr_count($string, PHP_EOL, 0, $offset);
    return $lineNo;
    }


    Funktionsweise:


Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!