for when you have old, bad php code that you need to move forward in versions / migrate
Last active
September 23, 2020 07:10
-
-
Save EntranceJew/653146fcdd0325a2715a477ed0757fff to your computer and use it in GitHub Desktop.
for when you're really screwed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// the really old obscure one that only works on php5.6 on Windows and not on linux anymore | |
class Memcache { | |
private $keys = []; | |
public function addServer($server, $port){ | |
// that's nice dear | |
} | |
public function set($key, $value, $some_flag_i_dont_care_about, $expire){ | |
$this->keys[$key] = $value; | |
} | |
public function get($key){ | |
return $this->keys[$key] ?? null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// replace old code using 'call_user_func_array' using 'bind_param' on an instance | |
// y'know, the kind that uses an array that leads with the type name? | |
// no? kids these days... | |
function preparedQuery($sql,$params) { | |
for ($i=0; $i<count($params); $i++) { | |
$sql = preg_replace('/\?/','"'.$params[$i].'"',$sql,1); | |
} | |
return $sql; | |
} | |
/* | |
$stmt = $mysqli->stmt_init(); | |
$query = preparedQuery($sql_query, $binds); | |
$stmt->prepare($query); | |
*/ | |
// original code stripped from the bowels of php.net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// if you are unfortunate enough to be in a database w/ register globals on, rip u | |
foreach (array_merge($_GET, $_POST, $_COOKIE) as $key => $val) { | |
global $$key; | |
$$key = (get_magic_quotes_gpc()) ? $val : addslashes($val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment