miércoles, 30 de diciembre de 2015

multi dimensional array

<?php

$multi=array("a"=>1,"b"=>2,"c"=>array("d"=>array("e"=>500)));

echo $multi['c']['d']['e'];

echo "<br>";

foreach( $multi['c']['d'] as $key=> $value){

echo " Key is $key  Value is $value <br>";

}

?>

Accessing array elements

Example #6 Accessing array elements
<?php
$array 
= array(
    
"foo" => "bar",
    
42    => 24,
    
"multi" => array(
         
"dimensional" => array(
             
"array" => "foo"
         
)
    )
);
var_dump($array["foo"]);var_dump($array[42]);var_dump($array["multi"]["dimensional"]["array"]);?>


string(3) "bar"
int(24)
string(3) "foo"

sábado, 26 de diciembre de 2015

php mysql function

list.php 

<?php

require_once("func.php");
require_once("setting.php");
$titles=Array("ID","Name","Path","Desc");

$record=array("list_field_id","_name","phone","call_status");

$query="select * from list";

$db_con=conect_db($setting[host],$setting[username],$setting[password],$setting[db]);

table($titles);

display_records($db_con,$query,$record);



?>



setting.php

<?php
/* db conection settings */
$setting=array("username"=>"root","password"=>"12340","host"=>"127.0.0.1","db"=>"dialer");



?>





func.php

<?php

/*db conection function */


function  conect_db($host,$username,$password,$db) {

$link = mysqli_connect("$host", "$username", "$password", "$db");


/* check connection */

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

else {

echo " Sucessfully conected to the database $db  ";

}
return $link;

}






/*table header function */


function table($titles){

echo"<br>
<center>
<table width=\"500\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#999999\" onMouseOver=this.bgColor=\"gold\" onMouseOut=this.bgColor=\"#CCCCCC\">
 <tr align=\"center\" bgcolor=\"#CCCCCC\">";

 foreach($titles as $value){
 echo "<td width=\"150\" nowrap=\"nowrap\"><strong>$value</strong></td>";
}

}



/*db display db elemtn function */


function display_records($link,$query,$record) {

if ($result = mysqli_query($link,$query)) {
$row_cnt mysqli_num_rows($result);

    
printf("Result set has %d rows.\n"$row_cnt);

    while ($row = mysqli_fetch_assoc($result)) {
  echo '<tr bgcolor="#FFFFFF" onMouseOver=this.bgColor="gold" onMouseOut=this.bgColor="white">';

foreach($record as $value) {
echo   "<td width=\"150\" nowrap=\"nowrap\">" .$row[$value] . "</td>";
}

}


}
else {

    printf(" Query failed: %s\n", mysqli_error($link));
exit();
}

}



?>

viernes, 25 de diciembre de 2015

php username checker function

<?php
$username=array("admin","root","guest");



function  username_check($uname,$user_list) {


if(in_array($uname,$user_list)){

echo " username  is already selected";

exit();
}



else{
echo " access granted<br>";
}
}


username_check("root1",$username);


echo <<<WELCOME

<b> Welcome to my website</b>
WELCOME;

?>

jueves, 24 de diciembre de 2015

mysqli_multi_query

<?php
$link 
mysqli_connect("localhost""my_user""my_password""world");
/* check connection */if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}
$query  "SELECT CURRENT_USER();";$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
/* execute multi query */if (mysqli_multi_query($link$query)) {
    do {
        
/* store first result set */
        
if ($result mysqli_store_result($link)) {
            while (
$row mysqli_fetch_row($result)) {
                
printf("%s\n"$row[0]);
            }
            
mysqli_free_result($result);
        }
        
/* print divider */
        
if (mysqli_more_results($link)) {
            
printf("-----------------\n");
        }
    } while (
mysqli_next_result($link));
}
/* close connection */mysqli_close($link);?>

domingo, 20 de diciembre de 2015

Sending MYSQL table to email


                                   Total of extensions 2
ExtensionTotal callsDurationCaller IDACTION
10227 Seconds"102" <102>
view
109615 Seconds"" <109>
view



Sending this table to an email address in with the htm tags, first  we  load the  table on  a variable

file_get_contents('http://65.181.118.232/php-project/counter.php');

65.181.118.232/php-project/counter.php i s the url where the table is showed

<?php
$homepage = file_get_contents('http://65.181.118.232/php-project/counter.php');
$body= $homepage;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail("ambiorixg12@gmail.com","Alert",$body,$headers);
echo "message sent";
?>




cleaning string

<?php


$var2="RemoteAddress: IPV4/UDP/74.208.164.60/5068";

$var2=explode("/",$var2);

foreach($var2 as $key=>$value) {

echo "$key $value<br>";

}

?>

sábado, 19 de diciembre de 2015

php sending email with linux mail function



system("echo \"$subject\" | mail -s \"$body\" ambiorixg12@gmail.com");

Function preg_replace() replace and regular expresion

<?php
   $copy_date = "Copyright 1999";
   $copy_date = preg_replace("([0-9]+)", "2000", $copy_date);
   
   print $copy_date;
?>
This will produce the following result −
Copyright 2000