Помощ за проверка за логната потребител

talevtehnology

Registered
Здравейте как да направя когато има логнат потребител да се ипзпълни това echo
Код:
 <?php 
$countfile = "count.dat"; 
$ipcounter = "today.dat"; 
$countdate = date("j-n-Y"); 
$visitorip = $_SERVER['REMOTE_ADDR']; 
$maxrecord = date("d.m.Y (H:i)"); 

if (!file_exists($ipcounter)) { $fp = fopen($ipcounter, 'w+'); } 
if (!file_exists($countfile)) { $fp = fopen($countfile, 'w+'); fwrite($fp, "0|0|0|1|$countdate|0|$maxrecord"); } 

$fcontents = file_get_contents($countfile); 
list($today, $yesterday, $total, $days, $nowdate, $max, $nowrecord) = explode("|", $fcontents); 

if($countdate != $nowdate) { 
$ipfile2 = fopen($ipcounter, 'w'); 
$line = "$visitorip\n"; 
fwrite($ipfile2, $line, strlen($line)); 
fclose($ipfile2); 

if($today > $max) { $max = $today; $nowrecord = $maxrecord; } 
$yesterday = $today; 
$today = 1; 
$total++; 
$days++; 

$fp = fopen($countfile, 'w'); 
fwrite($fp, "1|$yesterday|$total|$days|$countdate|$max|$nowrecord"); 
fclose($fp); 
} 

else { 
$ipfile = fopen($ipcounter, 'rb'); 
$line = array(); 
while (!feof($ipfile)) $line[]=fgets($ipfile,1024); 
for ($i=0; $i<(count($line)); $i++) { 
list($visitorip_x) = split("\n",$line[$i]); 
if ($visitorip == $visitorip_x) {$found = 1;} 
} 
fclose($ipfile); 

if (!$found) { 
$ipfile2 = fopen($ipcounter, 'ab'); 
$line = "$visitorip\n"; 
fwrite($ipfile2, $line, strlen($line)); 
fclose($ipfile2); 

$today++; 
$total++; 
if($today > $max) { $max = $today; $nowrecord = $maxrecord; } 
$fp = fopen($countfile, 'r+'); 
fwrite($fp, "$today|$yesterday|$total|$days|$countdate|$max|$nowrecord"); 
fclose($fp); 
} 
} 
if($days == 1) { $dendni = "ден"; } 
else { $dendni = "дни"; }
$sredno=ceil($total/$days); 

какво трябва да сложа за да се изпълни кода по долу ако има логнат потребител ???

echo "
<TABLE width='138px' height='56px' border='0' align='center'>
  <tr>
    <th width='132' height='38' scope='col'><div  style='font-family:verdana; font-size:11px; color:#00F; text-align:left'> 
     <b>Уникални посещения</b> 
    <br>Днес:<b>$today</b></br>
    <br>Вчера:<b>$yesterday</b></br>
    <br>Общо:<b>$total</b> за <b>$days</b>$dendni</b></br>
    <br>Средно дневно:<b>$sredno</b></br>
    <br>Рекорд:<b>$max</b><br> на <b>$nowrecord</b></p></br>
</div></th>
  </tr>
</table>
</td>"
?>
:)
 
ето това ми е кода за логин формата
Код:
<?php
$ses = session_id();
echo ('<center>
<div id="all">
<div id="header"></div>
<div id="menu">  
<a href="index1.php"class="style8">Начало </a>');
@$query = mysql_query("SELECT * FROM `users` WHERE session='$ses'");
@$red = mysql_num_rows($query);
if ($red != NULL) {
$my_id = mysql_result($query, "0", "id");
$my_ime = mysql_result($query, "0", "username");
if ($my_ime) {
$ls = mysql_query("SELECT * FROM message WHERE do = '$my_ime' AND procheten='ne'");
$lss = mysql_num_rows($ls);
$i=1;
if ($i <= $lss) {
echo ("<a href=\"box.php\">Съобщения  (<font color='red'><b>".$lss."</b></font>)</a>");
} else {
echo ("<a href=\"box.php\">Съобщения  (0)</a>");
}
echo ('
<a href="search.php"class="style8">Търси потребител </a>
');
}}
else {
echo ('<a href="register.php"class="style8">Регистрация   </a>
<a href="search.php"class="style8">Търси потребител</a></div>');
}
echo ('<div id="leftbar">');
@$query2 = mysql_query("SELECT * FROM `users` WHERE session='$ses'");
@$red2 = mysql_num_rows($query2);
if ($red2 != NULL) {
$my_id = mysql_result($query2, "0", "id");
$my_ime = mysql_result($query2, "0", "username");
setcookie('acivity', '1', time()+1800); 
if (isset($_COOKIE['activity'])) 
{ 
//Нещата, които излизат когато си логнат ! 
} 
else 
{ 
session_destroy(); 
}
echo ('');
$a = mysql_query("SELECT * FROM users WHERE username='$my_ime'") or die(mysql_error());
$b = mysql_fetch_array($a);
$level = $b['level'];
$c = mysql_query("SELECT * FROM user_levels WHERE id_level='$level'") or die(mysql_error());
$d = mysql_fetch_array($c);
$level_id = $d['id_level'];
echo ("[<b>  $my_ime  </b>]");
echo ('
<div align="left">
[-] <a href="members.php"class="style9">Потребители</a><br />
[-] <a href="editprofile.php"class="style9">Профил</a><br />
[-] <a href="logout.php"class="style9">Изход [ <b>'.$my_ime.'</b> ]</a>
</div><br />');
}
else {
echo ('
<div align="center">
<form action="login.php" method="post" > 
<table align="center" border="0"> 
<tr> 
<td align="left">Потребител</td>
</tr> 
<tr> 
<td><input name="username" type="text" id="username" /></td></tr>
<tr>
<td align="left">Парола</td>
</tr>
<tr>
<td><input name="password1" type="password" id="password1" /></td> 
</tr> 
<tr>
<td colspan="2" align="center">
<input name="login" type="submit" id="login" value="Вход" style=\'border: solid 1px black; cursor: pointer\'> 
</td>
</tr> 
</table> 
</form>
<center><a href="register.php">Регистрация</a></center>
</div>
');
}
?>
 
Ако съм оспял да те разбера :

Код:
  <?php
$countfile = "count.dat";
$ipcounter = "today.dat";
$countdate = date("j-n-Y");
$visitorip = $_SERVER['REMOTE_ADDR'];
$maxrecord = date("d.m.Y (H:i)");

if (!file_exists($ipcounter)) { $fp = fopen($ipcounter, 'w+'); }
if (!file_exists($countfile)) { $fp = fopen($countfile, 'w+'); fwrite($fp, "0|0|0|1|$countdate|0|$maxrecord"); }

$fcontents = file_get_contents($countfile);
list($today, $yesterday, $total, $days, $nowdate, $max, $nowrecord) = explode("|", $fcontents);

if($countdate != $nowdate) {
$ipfile2 = fopen($ipcounter, 'w');
$line = "$visitorip\n";
fwrite($ipfile2, $line, strlen($line));
fclose($ipfile2);

if($today > $max) { $max = $today; $nowrecord = $maxrecord; }
$yesterday = $today;
$today = 1;
$total++;
$days++;

$fp = fopen($countfile, 'w');
fwrite($fp, "1|$yesterday|$total|$days|$countdate|$max|$nowrecord");
fclose($fp);
}

else {
$ipfile = fopen($ipcounter, 'rb');
$line = array();
while (!feof($ipfile)) $line[]=fgets($ipfile,1024);
for ($i=0; $i<(count($line)); $i++) {
list($visitorip_x) = split("\n",$line[$i]);
if ($visitorip == $visitorip_x) {$found = 1;}
}
fclose($ipfile);

if (!$found) {
$ipfile2 = fopen($ipcounter, 'ab');
$line = "$visitorip\n";
fwrite($ipfile2, $line, strlen($line));
fclose($ipfile2);

$today++;
$total++;
if($today > $max) { $max = $today; $nowrecord = $maxrecord; }
$fp = fopen($countfile, 'r+');
fwrite($fp, "$today|$yesterday|$total|$days|$countdate|$max|$nowrecord");
fclose($fp);
}
}
if($days == 1) { $dendni = "ден"; }
else { $dendni = "дни"; }
$sredno=ceil($total/$days);

if (isset($_COOKIE['activity']))
{
echo "
<TABLE width='138px' height='56px' border='0' align='center'>
  <tr>
    <th width='132' height='38' scope='col'><div  style='font-family:verdana; font-size:11px; color:#00F; text-align:left'>
     <b>Уникални посещения</b>
    <br>Днес:<b>$today</b></br>
    <br>Вчера:<b>$yesterday</b></br>
    <br>Общо:<b>$total</b> за <b>$days</b>$dendni</b></br>
    <br>Средно дневно:<b>$sredno</b></br>
    <br>Рекорд:<b>$max</b><br> на <b>$nowrecord</b></p></br>
</div></th>
  </tr>
</table>
</td>";
}
else
{
echo "";
}
?>
 
не се получава аз се опраих ама не занм дали е пражилно иначе си работи супер
Код:
<?php 
$countfile = "count.dat"; 
$ipcounter = "today.dat"; 
$countdate = date("j-n-Y"); 
$visitorip = $_SERVER['REMOTE_ADDR']; 
$maxrecord = date("d.m.Y (H:i)"); 

if (!file_exists($ipcounter)) { $fp = fopen($ipcounter, 'w+'); } 
if (!file_exists($countfile)) { $fp = fopen($countfile, 'w+'); fwrite($fp, "0|0|0|1|$countdate|0|$maxrecord"); } 

$fcontents = file_get_contents($countfile); 
list($today, $yesterday, $total, $days, $nowdate, $max, $nowrecord) = explode("|", $fcontents); 

if($countdate != $nowdate) { 
$ipfile2 = fopen($ipcounter, 'w'); 
$line = "$visitorip\n"; 
fwrite($ipfile2, $line, strlen($line)); 
fclose($ipfile2); 

if($today > $max) { $max = $today; $nowrecord = $maxrecord; } 
$yesterday = $today; 
$today = 1; 
$total++; 
$days++; 

$fp = fopen($countfile, 'w'); 
fwrite($fp, "1|$yesterday|$total|$days|$countdate|$max|$nowrecord"); 
fclose($fp); 
} 

else { 
$ipfile = fopen($ipcounter, 'rb'); 
$line = array(); 
while (!feof($ipfile)) $line[]=fgets($ipfile,1024); 
for ($i=0; $i<(count($line)); $i++) { 
list($visitorip_x) = split("\n",$line[$i]); 
if ($visitorip == $visitorip_x) {$found = 1;} 
} 
fclose($ipfile); 

if (!$found) { 
$ipfile2 = fopen($ipcounter, 'ab'); 
$line = "$visitorip\n"; 
fwrite($ipfile2, $line, strlen($line)); 
fclose($ipfile2); 

$today++; 
$total++; 
if($today > $max) { $max = $today; $nowrecord = $maxrecord; } 
$fp = fopen($countfile, 'r+'); 
fwrite($fp, "$today|$yesterday|$total|$days|$countdate|$max|$nowrecord"); 
fclose($fp); 
} 
} 
if($days == 1) { $dendni = "ден"; } 
else { $dendni = "дни"; }
$sredno=ceil($total/$days); 
if ($my_ime){
echo ("
<TABLE width='138px' height='56px' border='0' align='center'>
  <tr>
    <th width='132' height='38' scope='col'><div  style='font-family:verdana; font-size:11px; color:#00F; text-align:left'> 
     <b>Уникални посещения</b> 
    <br>Днес:<b>$today</b></br>
    <br>Вчера:<b>$yesterday</b></br>
    <br>Общо:<b>$total</b> за <b>$days</b>$dendni</b></br>
    <br>Средно дневно:<b>$sredno</b></br>
    <br>Рекорд:<b>$max</b><br> на <b>$nowrecord</b></p></br>
</div></th>
  </tr>
</table>
</td>");
}
?>
 
Еми попринцип не е точно правилно, тей като ти така правиш проверка за изобщо някакво име със сесия в базата ти данни .. $my_ime променливата записва името на потребителя, който има записана сесия в базата данни ... по начина попринцип, който съм ти дал е идентичен с твоя, но аз проверявам за бисквитка която се създава като се логнеш и би трвябвало да работи, доколкото мога да разбера от кода ти ..
 

Back
Горе