miércoles, 7 de octubre de 2020

Send JSON data via POST with PHP cURL

 

The following example makes an HTTP POST request and send the JSON data to URL with cURL in PHP.

  • Specify the URL ($url) where the JSON data need to be sent.
  • Initiate new cURL resource using curl_init().
  • Setup data in PHP array and encode into a JSON string using json_encode().
  • Attach JSON data to the POST fields using the CURLOPT_POSTFIELDS option.
  • Set the Content-Type of request to application/json using the CURLOPT_HTTPHEADER option.
  • Return response as a string instead of outputting it using the CURLOPT_RETURNTRANSFER option.
  • Finally, the curl_exec() function is used to execute the POST request.
// API URL
$url 'http://www.example.com/api';

// Create a new cURL resource
$ch curl_init($url);

// Setup request to send json via POST
$data = array(
    
'username' => 'codexworld',
    
'password' => '123456'
);
$payload json_encode(array("user" => $data));

// Attach encoded JSON string to the POST fields
curl_setopt($chCURLOPT_POSTFIELDS$payload);

// Set the content type to application/json
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type:application/json'));

// Return response instead of outputting
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

// Execute the POST request
$result curl_exec($ch);

// Close cURL resource
curl_close($ch);

Receive JSON POST Data using PHP

The following example shows how you can get or fetch the JSON POST data using PHP.

  • Use json_decode() function to decoded JSON data in PHP.
  • The file_get_contents() function is used to received data in a more readable format.
$data json_decode(file_get_contents('php://input'), true);

miércoles, 30 de septiembre de 2020

php postgre

 install dependencies  sudo apt-get install php7.0-pgsql

yum install php-pgsql

restart apache

https://stackoverflow.com/questions/38981799/unable-to-install-php5-pgsql-on-ubuntu-16-04/42772824


<?php

   $host        = "host = hus-west-2.rds.amazonaws.com";

   $port        = "port = 5432";

   $dbname      = "dbname = product";

    $pass="dElm0zL";

$pid=$argv[1];

    $credentials = "user=phone  password=$pass";


   $db = pg_connect( "$host $port $dbname $credentials"  );

   if(!$db) {

      echo "Error : Unable to open database\n";

   } else {

      echo "Opened database successfully\n";

   }


   $sql =<<<EOF

      SELECT * FROM public.howardmillerinventory where "Clock"='$pid'

EOF;


   $ret = pg_query($db, $sql);

   if(!$ret) {

      echo pg_last_error($db);

      exit;

   }

   while($row = pg_fetch_row($ret)) {

      echo "Item# = ". $row[0] . "\n";

      echo "Stock= ". $row[1] ."\n";

      }

   echo "Operation done successfully\n";

   pg_close($db);

?>








domingo, 20 de septiembre de 2020

mysql export to csv

 https://makitweb.com/how-to-export-mysql-table-data-as-csv-file-in-php/

https://www.itechempires.com/2016/05/export-data-from-mysql-to-csv-using-php/

jueves, 17 de septiembre de 2020

php iptables

run   sudo visudo



root  ALL=(ALL) ALL


wwwrun ALL=NOPASSWD: /usr/sbin/iptables



<?php



$ip=$_SERVER['REMOTE_ADDR'];
echo " Welcome your IP $ip has been white listed";



 $web=shell_exec("sudo iptables -I INPUT 2 -m state --state NEW,RELATED,ESTABLISHED -m tcp -p tcp --dport 80 -s $ip -j ACCEPT");

 $sip=shell_exec("sudo iptables -I INPUT 2 -m state --state NEW,RELATED,ESTABLISHED -m udp -p udp --dport 28614 -s $ip -j ACCEPT"
?>

https://exain.wordpress.com/2007/11/24/execute-system-commands-via-php/

sábado, 25 de julio de 2020

mysql insert


<?php
$link = mysqli_connect("localhost", "root", "2224psss", "dialer");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "INSERT INTO `audio` (`audio_id`, `audio_name`, `audio_desc`, `audio_path`, `audio_size`, `audio_date`)
VALUES (NULL, 'audio_name', 'Audio desc', 'path', '100MB', CURRENT_TIMESTAMP)";
if(mysqli_query($link, $query)) {
printf ("New Record has id %d.\n", mysqli_insert_id($link));
}
else {
printf("Error: %s\n", mysqli_error($link));
}
/* close connection */
mysqli_close($link);
?>

martes, 21 de julio de 2020

IP list from a file

<?php
$ip=file_get_contents("http://149.248.59.112/ip_address.txt");
$ip=explode("\n",$ip);

foreach($ip as $value){
if(!empty($value)){
if (in_array("$value", $ip)) {
    echo "Got $value<br>";
}

else {

echo " I\'m sorry";
}

}

}
?>


196.179.2.65
154.104.154.150
102.158.71.137
196.179.45.12
102.156.151.182
196.179.27.230
41.227.238.97

domingo, 12 de julio de 2020

How to Reset Joomla Admin Password?

In ordinary way you can reset Joomla admin password from the admin panel through the User Manager. To do this, you have to be logged in as a Super Administrator.

What if it is impossible to reset Joomla admin passwords in such a way? For example, your website have been hacked, the previous admin person is no longer available or you just have forgotten the password. What you have to do?

Joomla is not simple thing. Joomla has some possibilities to reset admin password in other way. We will show you two methods, follow our instructions and get knowledge in how to reset Joomla admin password: