PHP - Move Array to Beginning or End of array
Move element to first array by key
$myArray = array('one' => $myArray['one']) + $myArray;
Move element to end array by key
$myArray = $myArray +array('one' => $myArray['one']);
$myArray = array('one' => $myArray['one']) + $myArray;
$myArray = $myArray +array('one' => $myArray['one']);
$date = "07/12/2010";
$your_date = date("Y-m-d", strtotime($date));
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], '(compatible; MSIE ')!==FALSE) {
//action for internet explorer
header('location:form-ie.php?idu='.$_GET['idu']);
} else {
//action for other browser
header('location:form.php?idu='.$_GET['idu']);
}
RewriteCond %{REQUEST_URI} !/folderName
<?php
$data = array(
'name' => array(
'first' => 'Randy',
'last' => 'Septian'
),
'phone' => array(
'personal' => array(
'mobile' => '085687xxxxx',
'home' => '0217788xxxx'
),
'office' => array(
'fax' => '0217788xxxx'
)
),
'gender' => 'male'
);
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('root');
function write(XMLWriter $xml, $data){
foreach($data as $key => $value){
if(is_array($value)){
$xml->startElement($key);
write($xml, $value);
$xml->endElement();
continue;
}
$xml->writeElement($key, $value);
}
}
write($xml, $data);
$xml->endElement();
echo $xml->outputMemory(true);
?>
$yesterday = date("Y-m-d",strtotime("-1 day"));echo $yesterday;
ALTER TABLE `table-name` CHANGE `table-name`. `field_name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
echo $testing;print_r(error_get_last());?>Output :
Array([type] => 8[message] => Undefined variable: testing[file] => C:\webfolder\test.php[line] => 2)
| Parameter | Description |
|---|---|
| error | Required. The error message to log |
| type | Optional. Specifies the error log type. Possible log types:
|
| destination | Optional. Specifies where to send the error message. The value of this parameter depends on the value of the "type" parameter |
| headers | Optional. Only used if the "type" parameter is "1". Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file. |
$test=2;
if ($test>1){error_log("A custom error has been triggered",1,"someone@example.com","From: webmaster@example.com");}?>
A custom error has been triggered
| Value | Constant | Description |
|---|---|---|
| 1 | E_ERROR | Fatal run-time errors. Errors that can not be recovered from. Execution of the script is halted |
| 2 | E_WARNING | Non-fatal run-time errors. Execution of the script is not halted |
| 4 | E_PARSE | Compile-time parse errors. Parse errors should only be generated by the parser |
| 8 | E_NOTICE | Run-time notices. The script found something that might be an error, but could also happen when running a script normally |
| 16 | E_CORE_ERROR | Fatal errors at PHP startup. This is like an E_ERROR in the PHP core |
| 32 | E_CORE_WARNING | Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core |
| 64 | E_COMPILE_ERROR | Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine |
| 128 | E_COMPILE_WARNING | Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine |
| 256 | E_USER_ERROR | Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error() |
| 512 | E_USER_WARNING | Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error() |
| 1024 | E_USER_NOTICE | User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error() |
| 2048 | E_STRICT | Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code |
| 4096 | E_RECOVERABLE_ERROR | Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler()) |
| 8191 | E_ALL | All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0) |
//Disable error reportingerror_reporting(0);
//Report runtime errorserror_reporting(E_ERROR | E_WARNING | E_PARSE);
//Report all errorserror_reporting(E_ALL);?>
//custom error handler functionfunction customError($errno, $errstr, $errfile, $errline) { echo "Custom error: [$errno] $errstr
"; echo " Error on line $errline in $errfile
"; }
//set user-defined error handlerset_error_handler("customError");
$test=2;
//trigger errorif ($test>1) { trigger_error("A custom error has been triggered"); }
//restore built-in error handlerrestore_error_handler();
//trigger error againif ($test>1) { trigger_error("A custom error has been triggered"); }?>
Custom error: [1024] A custom error has been triggeredError on line 14 in C:\webfolder\test.php
Notice: A custom error has been triggered in C:\webfolder\test.php on line 21
I want to enter comment with <script>alert('this xss attack'); </scipt>
function xss_filtering($text) {
$f = stripslashes (strip_tags (htmlspecialchars ($text, ENT_QUOTES)));
return $f;
}
$text_comment = xss_filtering($_POST['comment']);
SELECT * FROM user_table WHERE username=' ' OR 1=1;// ' AND password ='anything';
function sql_injection_filtering($data){
$filter = mysql_real_escape_string($data);
return $filter;
}
$username = sql_injection_filtering($_POST['username']);
$password = sql_injection_filtering($_POST['password']);
if (!ctype_alnum($username) OR !ctype_alnum($password)){
echo "Only alpha numeric";
} else {
echo "Login Succes";
}
Create directory to your home folder or wherever you want
Ex.
me@ubuntu:# mkdir /home/me/php
Navigate to that directory.
me@ubuntu:# cd /home/me/php
Download source.
Issue command as root.
me@ubuntu:/home/me/php# sudo apt-get source php5
me@ubuntu:/home/me/php# cd php5(Release Version)/ext/pcntl
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo phpize
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo ./configure
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo make
me@ubuntu:/home/me/php/php5(version)/ext/pcntl# sudo make install
Copy pcntl.so to /usr/lib/php5/200***(your version)/
Ex.
me@ubuntu:/home/me/php/php5(release_version)/ext/pcntl# cp /modules/pcntl.so /usr/lib/php5/200***(your version)/
Plus:
me@ubuntu:# echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini
If pcntl.ini doesn't exist, create it and issue the command written above.
_ _ _ _ _ _ _ _ _
| ID | Name |
-------------------
| 1 | Andre |
-------------------
| 2 | andre |
----------------------
<?php
function createRandomPassword($long=4) {
$charsL = "abcdefghijklmnopqrstuvwxyz";
$charsU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$int = "0123456789";
srand((double)microtime()*1000000);
$i = 1;
$pass = '' ;
$randStart = rand(1,3);
while ($i <= $long) {
if ($randStart == 1){
$num = rand() % 26;
$tmp = substr($charsL, $num, 1);
}
if ($randStart == 2){
$num = rand() % 26;
$tmp = substr($charsU, $num, 1);
}
if ($randStart == 3){
$num = rand() % 10;
$tmp = substr($int, $num, 1);
}
$pass = $pass . $tmp;
if ($randStart <= 2 )
$randStart = $randStart +1;
else
$randStart = $randStart -2;
$i++;
}
return $pass;
}
echo createRandomPassword(); //
copy folder activemq ke /opt/chmod 777 folder activemq
sudo /opt/activemq/bin/activemq start
akses http://localhost:8161/admin/ pada browser