Skip to content

Instantly share code, notes, and snippets.

View tim-cotten's full-sized avatar

Tim Cotten tim-cotten

View GitHub Profile
@tim-cotten
tim-cotten / php_bugs_4b.php
Created March 4, 2021 21:05
PHP Bugs: Confusing Non-Objects for Objects (Example B)
<?php
// ... Missile Command API called (malformed input) ...
$api_result = "{launch_override:true,msg:'abort'"; // <- notice the missing curly brace
$result = json_decode($api_result, true);
if ($result->launch_override) {
echo "Terminating launch sequence.";
exit();
}
@tim-cotten
tim-cotten / php_bugs_4a.php
Created March 4, 2021 20:59
PHP Bugs: Confusing Non-Objects for Objects (Example A)
<?php
// ... Missile Command API called ...
$api_result = "{launch_override:true,msg:'abort'}";
$result = json_decode($api_result, true);
if ($result->launch_override) {
echo "Terminating launch sequence.";
exit();
}
@tim-cotten
tim-cotten / php_bugs_3_2.php
Created March 4, 2021 03:15
PHP Bugs: The Curse of Magic Quotes (PHPMailer)
/**
* Encodes attachment in requested format. Returns an
* empty string on failure.
* @access private
* @return string
*/
function EncodeFile ($path, $encoding = "base64") {
if(!@$fd = fopen($path, "rb"))
{
$this->SetError($this->Lang("file_open") . $path);
@tim-cotten
tim-cotten / php_bugs_3_1.php
Created March 4, 2021 03:08
PHP Bugs: The Curse of Magic Quotes (PHPMailer)
////////////////////////////////////////////////////
// PHPMailer - PHP email class
//
// Class for sending email using either
// sendmail, PHP mail(), or SMTP. Methods are
// based upon the standard AspEmail(tm) classes.
//
// Copyright (C) 2001 - 2003 Brent R. Matzelle
//
// License: LGPL, see LICENSE
@tim-cotten
tim-cotten / php_bugs_2_5.php
Created March 3, 2021 16:44
PHP Bugs: Undefined Indexes and More Misspellings (Proof 5)
<?php
// Simple array of mixed keys and values
$arr = array(
0 => 'First',
1 => 'Second',
'Alpha' => 'Greek',
'FUN' => true,
'00' => 'Last',
0.328932 => 'test float',
32892.232 => 'test float 2'
@tim-cotten
tim-cotten / php_bugs_2c.php
Created March 3, 2021 16:34
PHP Bugs: Undefined Indexes and More Misspellings (Example C)
<?php
function getPage()
{
return $_SERVER['REQUEST_URI'];
}
$pages = array('' => 'index.php', 'home' => 'index.php', 'frequently-asked-questions' => 'faq.php', '404' => '404.php');
$uri = getPage();
$idx = array_key_exists($uri, $pages) ? $uri : '404';
@tim-cotten
tim-cotten / php_bugs_2b.php
Created March 3, 2021 15:30
PHP Bugs: Undefined Indexes and More Misspellings (Example B)
<?php
function getPage()
{
return $_SERVER['REQUEST_URI'];
}
$pages = array('' => 'index.php', 'home' => 'index.php', 'frequently-asked-questions' => 'faq.php');
@tim-cotten
tim-cotten / php_bugs_2a.php
Created March 3, 2021 15:19
PHP Bugs: Undefined Indexes and More Misspellings (Example A)
$sale['email_contents'] = $email_template['reciept_email'];
@tim-cotten
tim-cotten / php_bugs_2_4.php
Created March 3, 2021 15:04
PHP Bugs: Undefined Indexes and More Misspellings (Proof 4)
<?php
// Simple array of mixed keys and values
$arr = array(0 => 'First', 1 => 'Second', 'Alpha' => 'Greek', 'FUN' => true, '00' => 'Last');
$keys = array_keys($arr);
foreach ($keys as $key) {
echo "{$key} is " . gettype($key) . "\n";
}
// Output:
// 0 is integer
@tim-cotten
tim-cotten / php_bugs_2_3.php
Created March 3, 2021 14:59
PHP Bugs: Undefined Indexes and More Misspellings (Proof 3)
<?php
// Simple array of mixed keys and values
$arr = array(0 => 'First', 1 => 'Second', 'Alpha' => 'Greek', 'FUN' => true, '0' => 'Last');
$keys = array_keys($arr);
foreach ($keys as $key) {
echo "{$key} is " . gettype($key) . "\n";
}
// Output:
// 0 is integer