Download a file without showing its original URL

We can download a file from internet without showing its original url or in other sense, we can change the download link. here is the small php code that can download file by changing the url. <?php $url = ‘URL_HERE’; header(“Content-Type: application/force-download”); @readfile($url); ?>

Read More

Using MongoDB with PHP

To use MongoDB with PHP, you need to use MongoDB PHP driver. Download the driver from the url Download PHP Driver. Make sure to download the latest release of it. Now unzip the archive and put php_mongo.dll in your PHP extension directory (“ext” by default) and add the following line to your php.ini file − extension […]

Read More

POST method using curl

Post data to a url using CURL in PHP Simple Code :- <?php # Our new data $data = array( ‘user’ => 2, ‘pass’ => ‘2Test’ ); # Create a connection $url = ‘https://www.shivrajan.com/curl/get.php’; $ch = curl_init($url); # Form data string $postString = http_build_query($data, ”, ‘&’); # Setting our options curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, […]

Read More

Use command-line tools in PHP

Run shell commands in your Web applications Command-line overview This article considers the tools built into PHP that allow you to tap into the underlying shell environment and file system PHP is running on. PHP provides a number of functions for executing external commands, among them shell_exec(), exec(), passthru(), and system(). These commands are similar, […]

Read More

Prevent rendering your page inside an iframe using X-Frame-Options

Setting the reponse header: X-Frame-Options to DENY or SAMEORIGIN will prevent your page to be displayed in another site and will prevent most clickjacking attacks DENY <br/> will prevent your page completely from being displayed in an iframe.</br> php example: <?php header(‘X-Frame-Options: DENY’); ?> SAMEORIGIN <br/> will prevent you page from being displayed in other sites (in our case to allow displaying your […]

Read More

Save Images from html Remotely

Here is the simple php code to save the all images from html web page to server remotely :- <?php $doc = new DOMDocument(); @$doc->loadHTML($content); $tags = $doc->getElementsByTagName(‘img’); $count_img = 0; foreach ($tags as $tag) { $img = $tag->getAttribute(‘src’); $count_img++; $a = explode(“?”,$img); $image = $a[0]; $b = remoteImageUpload($image); $my_img = “http://www.jaihindutva.com/post/”.$b; $content = str_replace($img,$my_img,$content); […]

Read More

How to remove text between the tags in PHP

if you need to chop out the text portion from the url, turning, <a href=”link.html”>text</a> into <a href=”link.html”></a> you can do it simply by using  $str = preg_replace(‘#(<a.*?>).*?(</a>)#’, ‘$1$2’, $str);

Read More

How to rename uploaded file before saving it into a directory?

Use this code to rename the file automatically :- Instead of move_uploaded_file($_FILES[“file”][“tmp_name”], “../img/imageDirectory/” . $_FILES[“file”][“name”]); Use $temp = explode(“.”, $_FILES[“file”][“name”]);$newfilename = round(microtime(true)) . ‘.’ . end($temp);move_uploaded_file($_FILES[“file”][“tmp_name”], “../img/imageDirectory/” . $newfilename); Changed to reflect your question, will product a random number based on the current time and append the extension from the originally uploaded file.

Read More

Converting timestamp to time ago in PHP e.g 1 day ago, 2 days ago…

converting  a timestamp of the format 2009-09-12 20:57:19 and turn it into something like 3 minutes ago with PHP. Use example : echo time_elapsed_string(‘2016-05-01 00:22:35’);echo time_elapsed_string(‘@1367367755’); # timestamp inputecho time_elapsed_string(‘2016-05-01 00:22:35’, true); Input can be any supported date and time format. Output : 4 months ago4 months, 2 weeks, 3 days, 1 hour, 49 minutes, 15 seconds ago Function : […]

Read More