PHP Page Viewer

Echo89 1 Tallied Votes 449 Views Share

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

LastMitch commented: Thanks for sharing! +9
<?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
	}
}

?>
Member Avatar for LastMitch
LastMitch

@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

Echo89 9 Web Developer

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

Member Avatar for diafol
diafol

Question - what's the purpose of this code?

Echo89 9 Web Developer

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.