Hi,

I have few weblogs, example below
65.96.112.177 - - [27/Jan/2007:00:02:10 -0500] "GET /~jking/images/ralph.jpg HTTP/1.1" 200 66196
65.214.44.44 - - [27/Jan/2007:00:02:27 -0500] "GET /~jkabara/Research.htm HTTP/1.0" 200 4696
207.46.98.52 - - [27/Jan/2007:00:02:29 -0500] "GET /~mweiss/new/background.htm HTTP/1.0" 200 3905
207.46.98.52 - - [27/Jan/2007:00:02:35 -0500] "GET /%7Epaws/project_pacer.htm HTTP/1.0" 200 15645
207.46.98.52 - - [27/Jan/2007:00:02:36 -0500] "GET /%7Espring/patterns/node15.html#SECTION00042300000000000000 HTTP/1.1" 200 2641
65.214.44.44 - - [27/Jan/2007:00:02:42 -0500] "GET /~jkling/2110/week04.ppt HTTP/1.0" 200 1914280

Basically... I want to find out, which page did the user start browsing and which page he ended.

The output should be something like
Visitor 65.96.112.177 started browsing at page /~jking/images/ralph.jpg
Visitor 65.96.112.177 ended browsing at page /~jking/images/ralph.jpg
Visitor 65.214.44.44 started browsing at page /~jkabara/Research.htm
Visitor 65.214.44.44 ended browsing at page /~jkling/2110/week04.ppt
.
.
.
.


I wrote the code below assuming that, if the ip doesnt match at the 20th time...it means...the user ended his session. But it aint happening..could someone please help me do this...any other solutions/ideas are welcome

open (INF, $logfile);
	read INF, $file, -s INF;
	close INF;

	@lines = split /\n/, $file;

	foreach (@lines) {
	@values = split / /, $_;
	$visitors{$values[0]}++;
	}
	$maxcount=20;
	$timecounter=250;
	foreach $visitor (keys %visitors)
	{
		$flag = 0 ;
		foreach $logentry (@lines)
		{
			@values = split / /, $logentry;
			if($visitor eq $values[0])
			{
				$currentpage = $values[6];
				if($flag==0){
					print "\n Visitor " . $visitor . " started checking out the page";			
					print ":	 " .$values[6] . " ";
					$startpage = $values[6];
					$flag=1;
					$i=0;	
					$endpage = $values[6];
					}
				else{
					$endpage = $values[6];
					}
			}#if 
			else{
				$i++;
				}
			if($i > $maxcount) {print "\nLast Page Visited by " . $visitor . " was " .$endpage . " ";last;}				
			print "\ni=" .$i;
		}#for each line
	}#for each visitor
open (INF, $logfile);
read INF, $file, -s INF;
close INF;
 
@lines = split /\n/, $file;

foreach (@lines)
{
   @values = split / /, $_;
   $visitors{$values[0]}++;
   if ($visitors{$values[0]} == 1 )
   {
      # Get starting web page
      $report{$values[0]}[0] = "$values[6]";
      # When a user start browsing
      # considering this will be a first page as well as endpage
      $report{$values[0]}[1] = "$values[6]";  
   }
   else
   {
     # Get last web page
     $report{$values[0]}[1] = $values[6];   
   }
}

foreach my $key (keys %report)
{
  for my $i (0 .. 1 ) ## 0 -> For starting page 1-> For ending page
  {
    print "\n\nVisitor $key started browsing at page $report{$key}[$i]" if ($i == 0);
    print "\nVisitor $key ended browsing at page $report{$key}[$i]" if ($i == 1);
  }
}

Thank you buddy! You rock..it worked

open (INF, $logfile);
read INF, $file, -s INF;
close INF;

@lines = split /\n/, $file;

foreach (@lines)
{
   @values = split / /, $_;
   $visitors{$values[0]}++;
   if ($visitors{$values[0]} == 1 )
   {
      # Get starting web page
      $report{$values[0]}[0] = "$values[6]";
      # When a user start browsing
      # considering this will be a first page as well as endpage
      $report{$values[0]}[1] = "$values[6]";  
      $i=0;
      $report{$values[0]}[2] = 0;
   }
   else
   {
     # Get last web page
     $i = $report{$values[0]}[2];
     $patharray{$values[0]}[$i] = $values[6];
     $report{$values[0]}[1] = $values[6];   
     $i++;
     $report{$values[0]}[2] = $i;
   }
}

foreach my $key (keys %report)
{

    print "\n\nVisitor $key started browsing at page $report{$key}[0]";
    if($report{$key}[0] eq $report{$key}[1]) 
    { 
        print "\nVisitor ended browsing at the same page $report{$key}[0]"; 
    }
    else
    {
        print "\nHis path was"; $size=@patharray{$key};
        print $size;
        foreach my $k (0 .. $size)
        {
            print "\n $patharray{$key}[$k]";
        }
        print "\nVisitor $key ended browsing at page $report{$key}[1]";
    }   

}

I wanted the path as well..but when i execute the program. the system crashes.. i am trying to store the path in array ...path array... and the index of that value is store in the [2] value of report array....

could you please help me out in this

Concat the value of the path at "$report{$values[0]}[2]". End of the execution it got all the path details. Try the below codes.

open (INF, $logfile);
read INF, $file, -s INF;
close INF;

@lines = split /\n/, $file;

foreach (@lines)
{
  @values = split / /, $_;
  $visitors{$values[0]}++;
  if ($visitors{$values[0]} == 1 )
  {
     # Get starting web page
     $report{$values[0]}[0] = "$values[6]";
     # When a user start browsing
     # considering this will be a first page as well as endpage
     $report{$values[0]}[1] = "$values[6]";
     # Concat the path into index of 2
     $report{$values[0]}[2] .= "$values[6]\n";
     }
     else
     {
     # Get last web page
     $report{$values[0]}[1] = $values[6];
     # Concat the path into index of 2
     $report{$values[0]}[2] .= "$values[6]\n";
  }
}



foreach my $key (keys %report)
{
    print "\n\nVisitor $key started browsing at page $report{$key}[0]";
    if($report{$key}[0] eq $report{$key}[1])
    {
      print "\nVisitor $key ended browsing at the same page $report{$key}[0]";
    }
    else
    {
      print "\n$key Path Histroy Details : \n", $report{$key}[2];
    }
    print "\nVisitor $key ended browsing at page $report{$key}[1]";
}

could you please explain..what is the meaning of this part mentioned below..rest everything was understandable
thanks

@values = split / /, $_;
   $visitors{$values[0]}++;
   if ($visitors{$values[0]} == 1 )
   {

what is the meaning of ==1 there?

thanks

also.. i got the concatenated array..thanks for that

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.