Skip to content

php 쿠키의 생성 #159

Closed
Closed
@tomorrow9913

Description

@tomorrow9913

쿠키생성에서 오류가 있고 숫자가 정상적으로 올라가지 않네요... 해결 방법을 알 수 있을까요?

파일 권한은 777로 주었습니다

출력되는 내용
Warning: Cannot modify header information - headers already sent by (output started at /home/tomorrow9901/www/counter.php:2) in /home/tomorrow9901/www/counter.php on line 26

count.txt의 내용
2018-01-17,1,1

코드

<meta charset="utf-8">
<?
if ( !file_exists ( "count.txt") )
{
    $fp = fopen("count.txt", "w+") ;
    fclose($fp) ;
}
$count = file("count.txt") ;
$count = chop($count[0]) ;
$countdata = split(",",$count[0]);
$date =  strtotime($countdata[0]);
$daycount = (int)$countdata[1];
$counta = (int)$countdata[2];
$today = date("Y-m-d");
if ( !$_COOKIE["ip"] ){//쿠키가 없으면
  if($date == $today){//오늘 날짜와 txt의 날짜를 비교하여 같으면
    $daycount = $daycount + 1;// countday를 1 올린다.
  } else {//다르면
      $date = $today;//date를 오늘 날짜로 바꾼다.
      $daycount = 1 ;//daycount를 1로 한다.
    }
  $counta = $counta+1 ;
  $fp = fopen("count.txt", "w") ;
  fwrite($fp, "$date,$daycount,$counta") ;
  fclose($fp) ;
  SetCookie("ip", $REMOTE_ADDR, time() + 3600) ;//쿠키를 추가한다
}
echo $date." 의 방문자 수 : ".$daycount."<br>전체 방문자 수 : ".$counta;
?>

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions