Get random string in PHP

pass the string(char/number) and number of char you want in output.
function get_random_string($valid_chars, $length)
{
$random_string = “”;
$num_valid_chars = strlen($valid_chars);
for ($i = 0; $i < $length; $i++)
{
$random_pick = mt_rand(1, $num_valid_chars);
$random_char = $valid_chars[$random_pick-1];
$random_string .= $random_char;
}
return $random_string;
}

OR

function get_random_string($characters,$length)
{
$string = “”;
for ($p = 0; $p < $length; $p++) {
$string.= $characters[mt_rand(0, strlen($characters))];
}

return $string;
}

 

 

 

bin sh not found err for newly created user in Ubuntu

I created new user using command line as , $adduser [ new username]

After login in shell using the new user name, I unable to use my shell commands normally.
Eg: The shell doesn’t show the current working path, it will show $ only.

I searched on the web and I found some solution

$cd /etc/
$sudo cp passwd passwd.backup // copy as backup
$sudo gedit passwd

find line like /home/[new username]:/bin/sh
replace as /home/[new username]:/bin/bash

save and quite . Now working perfect. 🙂

INNER JOIN XPDO QUERY MODX

It is simple enough to get the XPDO inner join query in MODX.

The following example is to get the values form Table1 were Table1 name is equal to Table2 name.

$query = $modx->newQuery('table1');
$query->innerJoin('table2','table2_alias','table1.name=table2_alias.name');
$query->where(array(
'table2_alias.name' => 'Mark',
));
$result= $modx->getCollection('table1',$query);