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/ 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. 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? 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. 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? 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 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? 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 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 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"; 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 I want to get the webpage and save it locally to the archive directory 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"; 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 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 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); } ?> 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 Link to comment https://forums.phpfreaks.com/topic/297673-php-making-an-archive/#findComment-1518337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.