<?php
$date = date("Y-m-d");
$month = date("m");
$day = date("d");
$ri = date("w");
$counter = 0;
$monthdays = 0;
if(($month == 1)||($month == 3)||($month == 5)||($month == 7)||($month == 8)||($month == 10)||($month == 12)){
		$monthdays = 31;
}

else if($month == 2){
		$year = date("Y");
		if($year % 4 == 0){
		$monthdays = 29;
		}else{
		$monthdays = 28;
}
}
	
else if(($month == 4)||($month == 6)||($month == 9)||($month == 11)){
		$monthdays = 30;
}
else{
}

if($month==12){
	$year = date("Y") - 1;
	}else{
	$year = date("Y");
}

echo "$month $year $monthdays";
echo "</br>";

for($i=1;$i<$monthdays+1;$i++){
$date2 = "$year-$month-$i";
$ri2 = date( "w ",strtotime("$date2"));

if($ri2!=0){
$counter++;
}

echo "$date2 $ri2";
echo "<br/>";
}

echo "<br/>";
echo "$date $ri $counter";
?>