Created
October 16, 2018 14:30
-
-
Save tonypartridge/43c3d6f2f47d566fa8f7a28c9c4089a8 to your computer and use it in GitHub Desktop.
Bulk Session inserter for Joomla! replace the database connection details with your own database details.
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 | |
// Simple script to insert lots of sessions to Joomla _session table. | |
$limit = 20000; | |
// Database connection using mysqli | |
$dbname = 'j33jq'; | |
$dbuser = 'root'; | |
$dbpass = 'root'; | |
$dbhost = 'localhost'; | |
$dbprefix = 'j_'; | |
$sessionId = '48cmj6tmbc4gq33m7vubsod4bc'; | |
$db = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); | |
// clean out old test data | |
$db->query("DELETE FROM " . $dbprefix . "session wHERE session_id LIKE 'xx33xx33xx%'"); | |
for ($x = 0; $x <= $limit; $x++) { | |
$guest = rand(0, 1); | |
if ($guest == 0) | |
{ | |
$clientid = rand(0, 1); | |
} | |
else | |
{ | |
$clientid = 0; | |
} | |
$userid = 1000 + rand(1, 999999); | |
$username = $guest ? 'username' . $x : ""; | |
// This value isn't meaningful for this test | |
$data = 'joomla|s:736:"TzoydfgNDghofiyjS6mu95v6b3w4Wt34xhXdFfgJdlZ2lzdHJ5XFJlZ2lzdHJ5IjozOntzOjc6IgAqAGRhdGEiO086ODoic3RkQ2xhc3MiOjE6e3M6OToiX19kZWZhdWx0IjtPOjg6InN0ZENsYXNzIjo0OntzOjc6InNlc3Npb24iO086ODoic3RkQ2xhc3MiOjI6e3M6NzoiY291bnRlciI7aToxO3M6NToidGltZXIiO086ODoic3RkQ2xhc3MiOjM6e3M6NToic3RhcnQiO2k6MTUzOTMzNjY1ODtzOjQ6Imxhc3QiO2k6MTUzOTMzNjY1ODtzOjM6Im5vdyI7aToxNTM5MzM2NjU4O319czo4OiJyZWdpc3RyeSI7TzoyNDoiSm9vbWxhXFJlZ2lzdHJ5XFJlZ2lzdHJ5IjozOntzOjc6IgAqAGRhdGEiO086ODoic3RkQ2xhc3MiOjA6e31zOjE0OiIAKgBpbml0aWFsaXplZCI7YjowO3M6OToic2VwYXJhdG9yIjtzOjE6Ii4iO31zOjQ6InVzZXIiO086MjA6Ikpvb21sYVxDTVNcVXNlclxVc2VyIjoxOntzOjI6ImlkIjtpOjA7fXM6MTM6ImNoZWNrc2VjdXJpdHkiO2k6MTt9fXM6MTQ6IgAqAGl235434uaXRpYWxpemVkIjtiOjA7czo5OiJzZXB4fghcmF0b3IiO3M6MToiLiI7fQ=="'; | |
$date = new DateTime("- " . rand(0, 10000) . " seconds"); | |
$session_id = "xx33xx33xx" . base64_encode($sessionId . "some extra stuff to make the session id different" . $x); | |
$query = "INSERT INTO " . $dbprefix . "session (session_id, client_id, guest, time, data, userid, username) | |
VALUES ('$session_id', $clientid, 0, " . $date->getTimestamp() . ", '" . $data . "', $userid, $clientid)"; | |
// Run insert | |
if ($db->query($query)) { | |
} else { | |
echo 'Query failed<br>'; | |
echo $query . " <br>"; | |
echo mysqli_error($db); | |
die; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment