We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,376 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

PHP Page Viewer

By Caelan Stewart on Oct 11th, 2012 3:25 am

Here is a fully working PHP page viewer, set the variables $pages[] = "ANY URL HERE"; to suit your needs, and change the variable $max = 10; to however many views you want for each $page.

-Echo

<?php

$max = 10; // Set this to how many views you want per page
$time_to_wait = 3; // Time between views
set_time_limit(0);

$pages[] = "http://www.google.co.uk/"; // Copy and paste this line and change the link inside the quotes to just the plain video link nothing else.
$pages[] = "http://www.daniweb.com/";


foreach($pages as $page)
{
	$view_counter[$page] = 0;
	
	while($view_counter[$page] < $max)
	{
		$view_counter[$page] ++;
		
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $page);
        curl_setopt($curl, CURLOPT_FAILONERROR, true);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20121004 Firefox/15.2 PaleMoon/15.2"); // So you don't annoy google
		$return = curl_exec($curl);
		
		if($return)
		{
			echo "Success ($page): ".$view_counter[$page]."! <br />";
		}
		else
		{
			echo "Failure ($page): ".$view_counter[$page]."! <br />";
		}
		sleep($time_to_wait); // Allow a break to stop blacklisting
	}
}

?>

@Caelan Stewart

I finally figure out how this works. It's taking too long.

Is there another way to speed this up?

Even though you set it here:

$time_to_wait = 3; // Time between views

It's nice. I like it. It would be nicer if you adding comments how each function works.

I attach a image how the results looks like:

34

Attachments 3.png 5.28KB
LastMitch
Industrious Poster
4,202 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45

Set the variable $time_to_wait to 1, or even 0.5, to make it go faster.

Echo89
Junior Poster
109 posts since Mar 2012
Reputation Points: 9
Solved Threads: 4
Skill Endorsements: 0

Question - what's the purpose of this code?

diafol
Keep Smiling
Moderator
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

There is no purpose really, apart to get page views on specific threads on a websited.

Echo89
Junior Poster
109 posts since Mar 2012
Reputation Points: 9
Solved Threads: 4
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1181 seconds using 2.71MB