TeeGee Posted March 8, 2012 Share Posted March 8, 2012 hello there.. im planning to create a simple Online Users that is integrated to Facebook sdk. So far, i have the ff codes: index.php (this is where the online users listed) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Online Users</title> <link type="text/css" rel="stylesheet" href="style.css" /> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/ouser.js"></script> </head> <body> <table id="online"> </table> </body> </html> javascript file: $(document).ready( function() { setInterval (loadLog, 2500); }); function loadLog(){ $.ajax({ url: "onlineusers.html", cache: false, success: function(html){ $("#online").html(html); }, }); } test.php (This is my temporary file to test the Login authentication for FB.. THIS IS WORKING) <?php session_start(); require_once("src/facebook.php"); $config = array( 'appId' => '285873338131549', 'secret' => '56b9f71b9fd307a033aeeb725893fc89', ); $facebook = new Facebook($config); $user_id = $facebook->getUser(); ?> <?php if($user_id) { try { $user_profile = $facebook->api('/me','GET'); $profile = $user_profile['name']; $_SESSION['user'] = $profile; //PUT USER TO SESSION $_SESSION['user_id'] = $user_id; $line = file_get_contents("onlineusers.html"); $line = trim($line); // removes leading/trailing blank lines $line = explode("\n", $line); $line[] = '<tr><td><img src="https://graph.facebook.com/' . $_SESSION['user_id'] . '/picture"width="25"height="25"/></td><td>' . $_SESSION['user'] . '</td><td><a href="http://www.fb.com/' . $_SESSION['user_id'] . '" target="_blank">View Profile</a></td></tr>'; $line = array_unique($line); $line = implode("\n", $line); file_put_contents("onlineusers.html", $line); echo 'OK'; } catch(FacebookApiException $e) { $login_url = $facebook->getLoginUrl(); echo '<a href="' . $login_url . '">LOGIN</a>'; error_log($e->getType()); error_log($e->getMessage()); } } else { $login_url = $facebook->getLoginUrl(); echo '<a href="' . $login_url . '">LOGIN</a>'; } echo "<a href='logout.php'>Logout</a>"; ?> What it does is, it simple insert the picture and name of the user in a flat html file.. http://www.barkadafm.org/onlineusers/index.php Now, my problem is,. I dont know how to delete the pic and name if a user logs out or disconnect.. Example, my name is Name5 and i will connect / login using http://www.barkadafm.org/onlineusers/test.php for the first connect, my name and picture will be inserted to my flat html file.. Let's assume that there'are already 4 users online.. and the 5th data will be mine. Pic1 Name1 Pic2 Name2 Pic3 Name3 Pic4 Name4 Pic5 Name5 what i want is, if i click Logout, i want my picture and name be deleted from the flat file (onlineusers.html) and destroy my 2 variables set at test.php Please help me.. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/258547-help-fwrite-and-delete-function/ Share on other sites More sharing options...
TeeGee Posted March 9, 2012 Author Share Posted March 9, 2012 anyone??? Quote Link to comment https://forums.phpfreaks.com/topic/258547-help-fwrite-and-delete-function/#findComment-1325411 Share on other sites More sharing options...
trq Posted March 9, 2012 Share Posted March 9, 2012 You should have PHP output the online users dynamically, thre is no need to actually create any html file. Quote Link to comment https://forums.phpfreaks.com/topic/258547-help-fwrite-and-delete-function/#findComment-1325415 Share on other sites More sharing options...
TeeGee Posted March 10, 2012 Author Share Posted March 10, 2012 i need that. because i dont want to use too much CPU usage.. and i use jquery to refresh onlineusers.html every 2 seconds without quering. Quote Link to comment https://forums.phpfreaks.com/topic/258547-help-fwrite-and-delete-function/#findComment-1325709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.