Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

October 19, 2015

Random Strings Generator in PHP

Hello! if you are trying to create a random Number/ String Generator that never overlaps in PHP, you need to know how to use rand(), md5, and microtime().
for explanation, md5 is encrypting the number from microtime(random number that comes from the current time) and getting 0 to 26 numbers by using substr.
Try Copy and Pasting it to your Server with extension .php and run to get better idea of how this works.
Run example is on www.dogchats.com/a/1.php

<!DOCTYPE html>
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
   Random String Generator v0.1: <input type="number" name="fname">
   <input type="submit">
</form>

<table style="border: px solid #333;">

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
     // collect value of input field
     $number = $_REQUEST['fname'];

     if($number <= 0){
echo "<br>"; //Next Line
echo'<tr>';
echo '<td style="border: 1px solid #333">'."One or more please".'</td>';
echo'</tr>';
     }
else if($number >= 1001){
echo "<br>"; //Next Line
echo'<tr>';
echo '<td style="border: 1px solid #333">'."Number needs to be less than 1000".'</td>';
echo'</tr>';
     }
else {
echo "<br>"; //Next Line
echo '<td style="border: 1px solid #333;">'."Created Number:"."<br>".'</td>';
for($x=1;$x<=$number;$x++){

$rand = substr(md5(microtime()),rand(0,26),100);
echo '<tr>';
echo '<td style="border: 1px solid #333;">'.$rand."<br>".'</td>';
echo '</tr>';

 }

     }
}
?>
</table>
</body>
</html>

October 15, 2015

Using CURL for parsing websites on PHP

When a site you try to parse don't allow
file_get_contents("http:Site URL")
use CURL to parse


<?php

$head = array( "User-Agent: Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53", "Cookie: NNB=;" );
$site = "http://Name of the Site;
$a = curl_init(); curl_setopt($a, CURLOPT_URL, $site); curl_setopt($a, CURLOPT_HTTPHEADER, $head); curl_setopt($a, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/NNB");
$show  = curl_exec($a); curl_close($a);


echo $show;

?>