Tom8001 Posted August 6, 2015 Share Posted August 6, 2015 I am curious on how i can create an archive like this, http://d3ltasecurity.com/defaces/ Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/ Share on other sites More sharing options...
QuickOldCar Posted August 7, 2015 Share Posted August 7, 2015 That site inserts a url in a post form, a script visits the url and saves the html as a local file, records saved in a database linking the url to html file. Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518191 Share on other sites More sharing options...
Tom8001 Posted August 7, 2015 Author Share Posted August 7, 2015 how would you actually do this? the only way i can think of is by using file_get_contents(); and saving the html into a file, would this work? Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518213 Share on other sites More sharing options...
scootstah Posted August 7, 2015 Share Posted August 7, 2015 You could either use file_get_contents() with the allow_url_fopen config setting turned on, or you could just use CURL and save the response. Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518214 Share on other sites More sharing options...
Tom8001 Posted August 7, 2015 Author Share Posted August 7, 2015 how can you save it with CURL? Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518216 Share on other sites More sharing options...
Tom8001 Posted August 7, 2015 Author Share Posted August 7, 2015 I don't understand how i can make this work Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518222 Share on other sites More sharing options...
Tom8001 Posted August 8, 2015 Author Share Posted August 8, 2015 So, when the person enters a URL and the form is submitted, how can you save the webpage as a local file? Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518311 Share on other sites More sharing options...
scootstah Posted August 8, 2015 Share Posted August 8, 2015 Have a look at the manual. http://php.net/manual/en/function.curl-exec.php Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518315 Share on other sites More sharing options...
Tom8001 Posted August 8, 2015 Author Share Posted August 8, 2015 I'm new to learning curl and have a few errors, this is my code <?php if($_SERVER['REQUEST_METHOD'] == "POST") { $url = $_POST['url']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec($ch); curl_close($ch); $destination = "archive"; $file = fopen($destination, "w+"); fputs($file, $data); fclose($file); } ?> I'm trying to get the script to download a web page from a URL that has been entered in the HTML form. I'm getting these errors: Warning: fopen(archive): failed to open stream: Permission denied in C:\xampp\htdocs\defaces\index.php on line 14Warning: fputs() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\defaces\index.php on line 15 Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\defaces\index.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518322 Share on other sites More sharing options...
QuickOldCar Posted August 8, 2015 Share Posted August 8, 2015 You are trying to write to a directory and not a file $destination = "archive"; Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518323 Share on other sites More sharing options...
Tom8001 Posted August 8, 2015 Author Share Posted August 8, 2015 (edited) I want to get the webpage and save it locally to the archive directory Edited August 8, 2015 by Tom8001 Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518324 Share on other sites More sharing options...
QuickOldCar Posted August 8, 2015 Share Posted August 8, 2015 fputs(file,string,length) so you need the directory location and also a file name to save the data to $destination = "archive/source_1.html"; Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518333 Share on other sites More sharing options...
Tom8001 Posted August 8, 2015 Author Share Posted August 8, 2015 (edited) I got it to work fine, but i want to save the file with the url name in it and i am using the $url variable to do it and i get these errors, here is my code <?php if($_SERVER['REQUEST_METHOD'] == "POST") { $url = $_POST['url']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec($ch); curl_close($ch); $destination = "archive/".$url.""; // The error is coming from here, i put it as archive/source_1.html and it saved fine into the directory, but this gives me an error Warning: fopen(archive/http://example.com): failed to open stream: Invalid argument in C:\xampp\htdocs\defaces\index.php on line 14 $file = fopen($destination, "w+"); fputs($file, $data, strlen($data)); fclose($file); } ?> Errors: Warning: fopen(archive/http://example.com): failed to open stream: Invalid argument in C:\xampp\htdocs\defaces\index.php on line 14Warning: fputs() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\defaces\index.php on line 15Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\defaces\index.php on line 16 Edited August 8, 2015 by Tom8001 Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518335 Share on other sites More sharing options...
Tom8001 Posted August 8, 2015 Author Share Posted August 8, 2015 nvm i fixed it if($_SERVER['REQUEST_METHOD'] == "POST") { $url = $_POST['url']; $rand = rand(); $url = preg_replace('#^https?://#', '', $url); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec($ch); curl_close($ch); $destination = "archive/$rand-$url.html"; $file = fopen($destination, "w+"); fputs($file, $data, strlen($data)); fclose($file); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518336 Share on other sites More sharing options...
Tom8001 Posted August 8, 2015 Author Share Posted August 8, 2015 Just one more question though, how can i display every website that is submitted, how can i fetch all of them from the directory and echo them with a link. Like this for example http://d3ltasecurity.com/defaces/archive.php Quote Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518337 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.