cobusbo
-
Posts
224 -
Joined
-
Last visited
Posts posted by cobusbo
-
-
Ok so I tried this
$startat = 0; $getHowMany = 25; while($contacts = $api->get_contact_list('@Friends', $startat, $getHowMany) ) { $startat += $getHowMany; // advance starting point! foreach ($contacts->Contacts as $data) { ... do whatever you need to do ... } }
It seems to work but the only problem I got is that the function is slow. The app im using is giving me 10 seconds to get a response from my server and it seems like the loop takes longer. Is there a way to cleanup my code to make it more stable to save processioning time?
<html> <?php require_once('MxitAPI.php'); try { $key = '11111111111111111111111111111111111'; $secret = '1111111111111111111111111111111111111'; $api = new MxitAPI($key, $secret); if (isset($_GET) && isset($_GET['code'])) { $api->get_user_token($_GET['code'], 'http://*******************/chat2/share.php'); // Get Contacts $startat = 0; $getHowMany = 25; while($contacts = $api->get_contact_list('@Friends', $startat, $getHowMany) ) { //print_r($contacts); $startat += $getHowMany; // advance starting point! foreach ($contacts->Contacts as $data) { //echo $data->DisplayName."<br>"; $invite = $data->UserId; $invite1 = $invite . ','; echo "It worked"; /* generate the message */ $id = $_SERVER["HTTP_X_MXIT_USERID_R"]; $msg = "Hey! Come join me on {0}! And lets chat like a boss... :-P :-D"; $link = array( array( 'CreateTemporaryContact' => true, 'TargetService' => 'spamchat', 'Text' => 'Spam Chat' ) ); /* send the message */ $api->send_message($id, $invite1, $msg, 'true', $link); } } echo "It worked"; } elseif (isset($_GET) && isset($_GET['error']) && isset($_GET['error_description'])) { echo "<h2>There was an error requesting access from the API</h2>"; echo '<strong>Error:</strong> '. $_GET['error'] .'<br />'; echo '<strong>Error Description:</string> '. $_GET['error_description'] .'<br />'; } else { $api->request_access('************************', 'graph/read message/user'); } } catch (Exception $e) { echo $e->getMessage(); } ?> <a href="page.php">Back</a> </html>
-
Needs a rewrite of the pseudocode in that case
skip = 0 loop call get_contact_list() using skip skip += 25 if no contacts returned exit loop end if process contacts end loop
Is that better?
Ok so If I want to implement this into my code in the first post how would it look like? since im currently retrieving the contacts like this
foreach ($contacts->Contacts as $data) { echo $data->DisplayName."<br>"; $invite = $data->UserId; $invite1 = $invite . ',';
I'm not sure how to implement it? And so I do not have to specify anything in the limit(count) above and what about the filter?
-
pseudocode
start = 0 loop call get_contact_list() using start start += 25 if no contacts returned exit loop end if process contacts end loop
HI Barand, I'm not sure this will work because the get contact list function look as follow
/** * Get the social graph information for a MXit user with the given UserId contained in the * access token. * * Filters: @All, @Friends, @Apps, @Invites, @Connections (Default), @Rejected, @Pending, @Deleted, @Blocked * * Url: http://api.mxit.com/user/socialgraph/contactlist?filter={FILTER}&skip={SKIP}&count={COUNT} * * User Token Required * * Required scope: graph/read * * NOTE: You might expect count to return 2 items if you specify a value of 2, but it will return 3 items * So you should treat the value similar to an array value, ie specify 1 if you want 2 results */ public function get_contact_list($filter='', $skip=0, $count=0) { $this->_check_scope('get_contact_list', 'graph/read'); $url = $this->_base_user_api_url ."socialgraph/contactlist"; if ($filter != '') $url .= '?filter='. $filter; if ($skip != 0) { $url .= ($filter == '') ? '?' : '&'; $url .= 'skip='. $skip; } if ($count != 0) { $url .= ($filter == '' && $skip == 0) ? '?' : '&'; $url .= 'count='. $count; } $this->_api_headers(); $this->_call_api($url, 'GET'); return $this->result;
So as you can see in this case the 0 is the skipped contacts and count will be the maximum of 26 with each call I make
-
Hi I'm currently connecting to a API to retrieve info. The info I'm retrieving is in the form of Std Class Object.The problem I'm experiencing is that the results I get from one call is limited to 25. They say I should iterate it. But im not sure how to do so.My code so far
<html> <?php require_once('MxitAPI.php'); try { $key = '************************'; $secret = '*****************************'; $api = new MxitAPI($key, $secret); if (isset($_GET) && isset($_GET['code'])) { $api->get_user_token($_GET['code'], 'http://********************'); // Get Contacts $contacts = $api->get_contact_list('@Friends', 0, 25); //print_r($contacts); foreach ($contacts->Contacts as $data) { echo $data->DisplayName."<br>"; $invite = $data->UserId; $invite1 = $invite . ','; /* generate the message */ $id = $_SERVER["HTTP_X_MXIT_USERID_R"]; $msg = "Hey! Come join me on {0}! And lets chat like a boss... :-P :-D"; $link = array( array( 'CreateTemporaryContact' => true, 'TargetService' => '********', 'Text' => '*****' ) ); /* send the message */ $api->send_message($id, $invite1, $msg, 'true', $link); } } elseif (isset($_GET) && isset($_GET['error']) && isset($_GET['error_description'])) { echo "<h2>There was an error requesting access from the API</h2>"; echo '<strong>Error:</strong> '. $_GET['error'] .'<br />'; echo '<strong>Error Description:</string> '. $_GET['error_description'] .'<br />'; } else { $api->request_access('***********************', 'graph/read message/user'); } } catch (Exception $e) { echo $e->getMessage(); } ?> <a href="page.php">Back</a> </html>
They say I should turn
$contacts = $api->get_contact_list('@Friends', 0, 25);
into a loop but not sure how to do so
the 0 is the files to skip and 25 is the amount to retrieve with each call.
they say
More info can be found here regarding the API im trying to use
with print_r option my object looks like
stdClass Object ( [Contacts] => Array ( [0] => stdClass Object ( [DisplayName] => Zyco [FirstName] => zyco [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426134583000+0200)/ [LastOnline] => /Date(1426139350470+0200)/ [StatusMessage] => ) [UserId] => 0769114834 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [1] => stdClass Object ( [DisplayName] => cobusbo [FirstName] => Cobus [LastName] => Botma [State] => stdClass Object ( [Availability] => 2 [IsOnline] => 1 [LastModified] => /Date(1426162593000+0200)/ [LastOnline] => /Date(1426180367476+0200)/ [Mood] => 0 [StatusMessage] => checkout spamchat ) [UserId] => 27765238453 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [2] => stdClass Object ( [DisplayName] => Bassmaker [FirstName] => Stefan [LastName] => Hattingh [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425535612000+0200)/ [LastOnline] => /Date(1426232999571+0200)/ [StatusMessage] => Lesson learned!!!! Never fall inlove!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ) [UserId] => 27828456765 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [3] => stdClass Object ( [DisplayName] => SHERIFF [FirstName] => ``ॐ☀☺ॐB.I.G5☺™♦.+LIONKIng [LastName] => ँ๏°˚ _♥_☺™♦☀LORDMINATI☀☺™♦๏° [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1420610808000+0200)/ [LastOnline] => /Date(1426171691976+0200)/ [StatusMessage] => #ff425a #ff425aLaVeyan sHaitAn Bible. ) [UserId] => m11231391002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [4] => stdClass Object ( [DisplayName] => HunterPoint. [FirstName] => Caroline [LastName] => Boot [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426227463000+0200)/ [LastOnline] => /Date(1426240850456+0200)/ [StatusMessage] => Friend isn't about who you've know the longest it's about who walked into your life said "I'm here for you" and proved it. ) [UserId] => m18323190002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [5] => stdClass Object ( [DisplayName] => $Sugar$ $Max$ [FirstName] => $sugar$ $max$ [LastName] => Sugar$ $max$ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425995353000+0200)/ [LastOnline] => /Date(1426237305719+0200)/ [StatusMessage] => ) [UserId] => m19055694002 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [6] => stdClass Object ( [DisplayName] => .-.-.-KID☀BIG [FirstName] => *#c0c00c.+.+.+KID #c0c0c0BIG* [LastName] => *#c0c0c0.+.+.+BUMS#00ff00HAKA* [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424843034000+0200)/ [LastOnline] => /Date(1425665935177+0200)/ [StatusMessage] => ) [UserId] => m24542119002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [7] => stdClass Object ( [DisplayName] => Kλzεhιτsυjι [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425991633000+0200)/ [LastOnline] => /Date(1425991773513+0200)/ [StatusMessage] => #9966fb phone broken ) [UserId] => m25912500002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [8] => stdClass Object ( [DisplayName] => (H)FATIMA(H) [FirstName] => /#ff0000Fatima/ [LastName] => /#ff0000Japhta/ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425912639000+0200)/ [LastOnline] => /Date(1426239237672+0200)/ [StatusMessage] => Busy..... Flaming spirit-: SITTER ) [UserId] => m35370741002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [9] => stdClass Object ( [DisplayName] => ��m�H� W�YB�Y [FirstName] => Francois Barnard [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426006669000+0200)/ [LastOnline] => /Date(1426183951042+0200)/ [StatusMessage] => ...... Ķãmãķãżī Wãřłøřđś .... If anyone knows coding pls msg me ... or if u know wapka msg me pls ((( Checkout Extreme_gamers ))) ) [UserId] => m37042581002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [10] => stdClass Object ( [DisplayName] => *#ff0000 #0000ffXena* [FirstName] => Km vnd yt [LastName] => Vra jw nek [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424576823000+0200)/ [LastOnline] => /Date(1424577160006+0200)/ [StatusMessage] => .+#0000ff ) [UserId] => m40566397002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [11] => stdClass Object ( [DisplayName] => {{*BL!TZKR!3G#]] [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425809938000+0200)/ [LastOnline] => /Date(1425818270545+0200)/ [StatusMessage] => Cheers Galaxy Wars. ) [UserId] => m41544489002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [12] => stdClass Object ( [DisplayName] => Lord of chaose [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426188520000+0200)/ [LastOnline] => /Date(1426224169262+0200)/ [StatusMessage] => ) [UserId] => m42930422002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [13] => stdClass Object ( [DisplayName] => Morning-staR• [FirstName] => Apocalypse [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426016522000+0200)/ [LastOnline] => /Date(1426236913282+0200)/ [StatusMessage] => D.N.A femceE's Crew be Making a one hella sick tour around DBN. Lol err don't even ask about the Males Crew but i'm happy for all my gals daddy cant wait for ya'll to come back so we can start eating some MoOLa(((LMAO))) ) [UserId] => m43239048002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [14] => stdClass Object ( [DisplayName] => #Ff0000*.+.+.+©£MP£ROR©#Ff0000*.+.+.+ [FirstName] => #Ff0000*.+.+JUMONG#Ff0000*.+.+ [LastName] => #cc00cc*.+.+DYNA§TY#Ff0000*.+.+ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1421736155000+0200)/ [LastOnline] => /Date(1426225275110+0200)/ [StatusMessage] => #ff00ff®eally.. Visit my download portal- VENTRICK | Home Of Downloads Remember d sabbath dat 2 kip it holy. I can do all tins 2ru christ which streghteneth me! ) [UserId] => m46623264004 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [15] => stdClass Object ( [DisplayName] => kira [FirstName] => Kira [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426111312000+0200)/ [LastOnline] => /Date(1426231189633+0200)/ [StatusMessage] => Havent! ) [UserId] => m48340699002 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [16] => stdClass Object ( [DisplayName] => DEATHANGEL [FirstName] => DEATH [LastName] => ANGEL [State] => stdClass Object ( [Availability] => 3 [IsOnline] => 1 [LastModified] => /Date(1426239062000+0200)/ [LastOnline] => /Date(1426239536392+0200)/ [Mood] => 1 [StatusMessage] => ) [UserId] => m49191486002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [17] => stdClass Object ( [DisplayName] => Shadow Reaper [FirstName] => dont [LastName] => know [State] => stdClass Object ( [Availability] => 1 [IsOnline] => 1 [LastModified] => /Date(1426189573000+0200)/ [LastOnline] => /Date(1426237783400+0200)/ [Mood] => 6 [StatusMessage] => Leave me alone not in the mood...tik verby ) [UserId] => m51256041002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [18] => stdClass Object ( [DisplayName] => 《■□●◆8-)¿¥¤UNG §K@T£R¿8-)●■●♧》 [FirstName] => #fe333d??? [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425840233000+0200)/ [LastOnline] => /Date(1425126238187+0200)/ [StatusMessage] => #669966 ) [UserId] => m52626156002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [19] => stdClass Object ( [DisplayName] => .+_*#ffff00ICON*_ [FirstName] => .+*MCKINGO #ffff00 [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424897461000+0200)/ [LastOnline] => /Date(1425331624085+0200)/ [StatusMessage] => THE ICON NOT AND NEVER WILL BE XCON.AM THE APEX OF APEX PREDATORS ) [UserId] => m56408943004 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [20] => stdClass Object ( [DisplayName] => *N-R* [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424209196000+0200)/ [LastOnline] => /Date(1426181775833+0200)/ [StatusMessage] => ) [UserId] => m58722247002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [21] => stdClass Object ( [DisplayName] => ZIYAD [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426097756000+0200)/ [LastOnline] => /Date(1426182338901+0200)/ [StatusMessage] => I'm not here right now ) [UserId] => m60626483002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [22] => stdClass Object ( [DisplayName] => king•othello [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1426175909000+0200)/ [LastOnline] => /Date(1426176930152+0200)/ [StatusMessage] => ) [UserId] => m61831903002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [23] => stdClass Object ( [DisplayName] => #c0c00c.+.+.+*Mxit hacker* [FirstName] => $Mxit hacker$ [LastName] => $Mxit hacker$ [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1423285744000+0200)/ [LastOnline] => /Date(1423285748616+0200)/ [StatusMessage] => 2015 comes with new cheat tricks tht i created [Image] [Image] ) [UserId] => m62798876002 [Blocked] => [Group] => MXit [ContactType] => 0 [SubscriptionType] => 66 ) [24] => stdClass Object ( [DisplayName] => james basson [FirstName] => [LastName] => [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1425222833000+0200)/ [LastOnline] => /Date(1425224038803+0200)/ [StatusMessage] => ¿Grim Give¿ ) [UserId] => m63089464002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) [25] => stdClass Object ( [DisplayName] => Kizer Dengram [FirstName] => Clinton [LastName] => Ifeanyichukwu [State] => stdClass Object ( [Availability] => 4 [IsOnline] => [LastModified] => /Date(1424621304000+0200)/ [LastOnline] => /Date(1426236525690+0200)/ [StatusMessage] => Ooh Lord My havenly father, as i arrange my wonderful bed (Future) so i will lie on it... But lord as i am part of your family, please lord come and help me to arrange my Bed (My Future) coz only me cant arrange a whole wide Bed, for fear of Wolves! Amen! ) [UserId] => m63748006002 [Blocked] => [Group] => Galaxy Universe Admin [ContactType] => 0 [SubscriptionType] => 66 ) ) )
this is only the first 26 people info on my contact list I need to get a way to iterate it when the call is done with the first 26 to move on to the next 26. and then the next 26 etc.I looked at $contacts = $api->get_contact_list('@Friends', 0, 25) and saw the 0 for skipped items and 25 for page limit. is there maybe a way to create a loop to say with the first call skip 0 with the second recall skip the first 25 and with 3rd recall skip the first 50 till its done... -
This is my code
$testip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($testip)) { $testip = "Debater"; } $result = mysql_query("SELECT * FROM pm WHERE mxitid = \"$testip\" ORDER BY id DESC LIMIT $offset, $rowsperpage")or trigger_error("SQL", E_USER_ERROR); while($row = mysql_fetch_array($result) or die($result."<br/><br/>".mysql_error())) { $name = $row['username']; $mid = $row['mxitid']; $message = $row['message']; $id = $row['id']; $date = $row['time']; $myip = $row['ip']; $delete = '<a href="http://guniverse.hol.es/chat/pm.php?option=Delete&id=' . $id . '">Delete</a>'; $reply = '<a href="http://guniverse.hol.es/chat/pm.php?option=' . 'reply'. '&nname=' . $name . '&ip=' . $myip .'">Reply</a>'; echo '<b>' . $name . ':</b> <i>' . $message . ' - ' . '<span style="color:#828282">' . date( 'D H:i:s', $date ) . '</span> ' . $delete . " " . $reply .'</i><br>'; if($_GET['option']=='reply') { $mxitid = $_GET["ip"]; $result = mysql_query("SELECT * FROM Users2 WHERE mxitid='".$mxitid."'", $conn); $myrow = mysql_fetch_array($result); ?> <form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>"> Type in your message...<br> <input name="message" class="StringyChatFrm" type="text" size="20" maxlength="<? echo $name_size; ?>" value="<? echo $myrow["Username"]?>"> <br> <input name="message1" class="StringyChatFrm" type="submit" value="Update"> </form> <? } if ($_POST["message1"]) { $ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($ip)) { $ip = "Debater"; } $result = mysql_query("SELECT * FROM Users2 WHERE mxitid = \"$ip\""); $id = $_GET["id"]; $nname = $_GET["nname"]; $ip1 = $_GET["ip"]; $banby2 = $_SERVER["HTTP_X_MXIT_USERID_R"]; $row = mysql_fetch_array($result); $mxitid = $row['mxitid']; $naam = $row['Username']; $rank = $row['rank']; $date = date("U"); $mxitid = $_GET["ip"]; $message = $_POST["message"]; $query = "INSERT INTO pm (username,mxitid,message,time) VALUES (\"$naam\",\"$ip1\",\"$message\",\"$date\")"; $result = mysql_query($query, $conn) or die("Invalid query: " . mysql_error()); $query5 = "SELECT * FROM broadcast"; $result1 = mysql_query($query5) or die(mysql_error()); $users = array(); while($row = mysql_fetch_array($result1)){ if ($row['onorof'] != '') $users[] = $row['onorof']; } $batchSize = 50; // set size of your batches $batches = array_chunk($users, $batchSize); require_once ('MxitAPI.php'); /* Instantiate the Mxit API */ $key = 'a82a9fb77a9d435b8c8c066a5bbd9959'; $secret = 'c3a4f316361e4a7a8573bfe6c8652560'; $app = 'spamchat'; $nick = urldecode($_SERVER['HTTP_X_MXIT_NICK']); $admin = array('m70141099002' , 'Debater', '27765238453', ''); $moderator = array('m52626156002', 'm51256041002' , 'm50079252002', '27723289551'); $testip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if (in_array($testip, $admin)){ $col = "#ff0000"; $message1 = "#ff0000" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; } elseif (in_array($testip, $moderator)){ $col = "#4CA64C"; $message1 = "#4CA64C" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; } else{ $col = "#000000"; $message1 = "#000000" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; } if(!isset($nick)) { $nick = "Debater"; } $message = $_POST["message"]; $message1 = "$col" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; $api = new MxitAPI($key, $secret); $api->get_app_token('message/send'); foreach ($batches as $batch) { $list = implode(',', $batch); // process the batch list here $api->send_message($app, $ip1, $message1, 'true'); } echo "Message has been Sent!"; } }
Shows on page
and after submiting the form I get the error
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u342037492/public_html/chat/pm.php on line 83 1
Line 83 is
$result = mysql_query("SELECT * FROM pm WHERE mxitid = \"$testip\" ORDER BY id DESC LIMIT $offset, $rowsperpage")or trigger_error("SQL", E_USER_ERROR); while($row = mysql_fetch_array($result) or die($result."<br/><br/>".mysql_error())) {
of the above code.
Where am I going wrong?
Ok so I changed the code to
$sql = "SELECT * FROM pm WHERE mxitid = \"$testip\" ORDER BY id DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn)or trigger_error("SQL", E_USER_ERROR); while($row = mysql_fetch_array($result)) {
the resource 4 error is gone but I still get the error
mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u342037492/public_html/chat/pm.php on line 84
-
This is my code
$testip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($testip)) { $testip = "Debater"; } $result = mysql_query("SELECT * FROM pm WHERE mxitid = \"$testip\" ORDER BY id DESC LIMIT $offset, $rowsperpage")or trigger_error("SQL", E_USER_ERROR); while($row = mysql_fetch_array($result) or die($result."<br/><br/>".mysql_error())) { $name = $row['username']; $mid = $row['mxitid']; $message = $row['message']; $id = $row['id']; $date = $row['time']; $myip = $row['ip']; $delete = '<a href="http://guniverse.hol.es/chat/pm.php?option=Delete&id=' . $id . '">Delete</a>'; $reply = '<a href="http://guniverse.hol.es/chat/pm.php?option=' . 'reply'. '&nname=' . $name . '&ip=' . $myip .'">Reply</a>'; echo '<b>' . $name . ':</b> <i>' . $message . ' - ' . '<span style="color:#828282">' . date( 'D H:i:s', $date ) . '</span> ' . $delete . " " . $reply .'</i><br>'; if($_GET['option']=='reply') { $mxitid = $_GET["ip"]; $result = mysql_query("SELECT * FROM Users2 WHERE mxitid='".$mxitid."'", $conn); $myrow = mysql_fetch_array($result); ?> <form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>"> Type in your message...<br> <input name="message" class="StringyChatFrm" type="text" size="20" maxlength="<? echo $name_size; ?>" value="<? echo $myrow["Username"]?>"> <br> <input name="message1" class="StringyChatFrm" type="submit" value="Update"> </form> <? } if ($_POST["message1"]) { $ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($ip)) { $ip = "Debater"; } $result = mysql_query("SELECT * FROM Users2 WHERE mxitid = \"$ip\""); $id = $_GET["id"]; $nname = $_GET["nname"]; $ip1 = $_GET["ip"]; $banby2 = $_SERVER["HTTP_X_MXIT_USERID_R"]; $row = mysql_fetch_array($result); $mxitid = $row['mxitid']; $naam = $row['Username']; $rank = $row['rank']; $date = date("U"); $mxitid = $_GET["ip"]; $message = $_POST["message"]; $query = "INSERT INTO pm (username,mxitid,message,time) VALUES (\"$naam\",\"$ip1\",\"$message\",\"$date\")"; $result = mysql_query($query, $conn) or die("Invalid query: " . mysql_error()); $query5 = "SELECT * FROM broadcast"; $result1 = mysql_query($query5) or die(mysql_error()); $users = array(); while($row = mysql_fetch_array($result1)){ if ($row['onorof'] != '') $users[] = $row['onorof']; } $batchSize = 50; // set size of your batches $batches = array_chunk($users, $batchSize); require_once ('MxitAPI.php'); /* Instantiate the Mxit API */ $key = 'a82a9fb77a9d435b8c8c066a5bbd9959'; $secret = 'c3a4f316361e4a7a8573bfe6c8652560'; $app = 'spamchat'; $nick = urldecode($_SERVER['HTTP_X_MXIT_NICK']); $admin = array('m70141099002' , 'Debater', '27765238453', ''); $moderator = array('m52626156002', 'm51256041002' , 'm50079252002', '27723289551'); $testip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if (in_array($testip, $admin)){ $col = "#ff0000"; $message1 = "#ff0000" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; } elseif (in_array($testip, $moderator)){ $col = "#4CA64C"; $message1 = "#4CA64C" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; } else{ $col = "#000000"; $message1 = "#000000" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; } if(!isset($nick)) { $nick = "Debater"; } $message = $_POST["message"]; $message1 = "$col" . "You Received a Mailbox message from " . $naam . " " ."\$Refresh\$"; $api = new MxitAPI($key, $secret); $api->get_app_token('message/send'); foreach ($batches as $batch) { $list = implode(',', $batch); // process the batch list here $api->send_message($app, $ip1, $message1, 'true'); } echo "Message has been Sent!"; } }
Shows on page
Resource id #5
and after submiting the form I get the error
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u342037492/public_html/chat/pm.php on line 83 1
Line 83 is
$result = mysql_query("SELECT * FROM pm WHERE mxitid = \"$testip\" ORDER BY id DESC LIMIT $offset, $rowsperpage")or trigger_error("SQL", E_USER_ERROR); while($row = mysql_fetch_array($result) or die($result."<br/><br/>".mysql_error())) {
of the above code.
Where am I going wrong?
-
I'm currently making use of arrays to modify my font colors in my chat script for example
$admin = array('m70141099002' , 'Debater', '27765238453', ''); $moderator = array('m52626156002', 'm57010835002' , 'm50079252002', '27723289551', 'm38565659002'); $testip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($name)) { $name = "Debater"; } if(!isset($testip)) { $testip = "Debater"; } ////////////////This is for Admin Permission Users////////////// if (in_array($testip, $admin)) { if (in_array($list['StringyChat_ip'], $admin)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '</span>'. '<span style="color:red">' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $moderator)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:green">' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $pc)) { print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:purple">' . '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $helper)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:blue">' . '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $globalhelper)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:blue">' . '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } else { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:#0365B8">' . '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } }
This printout will show all the users matching the testip within the admin array, I got the same printout for moderators as well.
Well the real problem I'm experiencing right now is to use my database to calculate the color it should display.
I got 3 tables at this stage
Table 1: Users2
Layout
ID, Username, mxitid, nick, phone and rank
This table is where I store the usernames of people if they register and give them the rank value of 6
Table 2: ranks_colors
Layout
Type, rank, color1, color2, color3, color4
Admin, 1, red, blue, orange, purple
Mod, 2, green, pink, yellow, black
etc... upto 6 wich is Normal
This table is where I specify Type like Administrator rank 1 and 4 colors he can use within hes text printout
Table 3: StringyChat
Layout
id, ip, name, message, time, device, rank
This is basically where the messages that is being send will be stored each in its own row with the specified rank number.
The problem I'm currently struggling with is the ranks I want each rank type font to be different for example in the above Table 2. If admin all the messages send by admin must be red. All the mod messages must be green etc.
How can I change from the array way to mysql by using the ranks system?
I tried to recall it with
$resultr = mysql_query("SELECT * FROM Users2 WHERE mxitid = \"$ip\""); $rowr = mysql_fetch_array($resultr); $rank = $rowr['rank']; $mxitidd = $rowr['mxitid']; $resultc = mysql_query("SELECT * FROM ranks_color WHERE rank = \"$rank\""); $rowc = mysql_fetch_array($resultc); $rank2 = $rowc['rank']; $color1 = $rowc['color1']; $color2 = $rowc['color2']; $color3 = $rowc['color3']; $color4 = $rowc['color4'];
but it didn't work only got it that everyones text was one color not according to the colors of the permissions.
-
I'm currently making use of arrays to modify my font colors in my chat script for example
$admin = array('m70141099002' , 'Debater', '27765238453', ''); $moderator = array('m52626156002', 'm57010835002' , 'm50079252002', '27723289551', 'm38565659002'); $testip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($name)) { $name = "Debater"; } if(!isset($testip)) { $testip = "Debater"; } ////////////////This is for Admin Permission Users////////////// if (in_array($testip, $admin)) { if (in_array($list['StringyChat_ip'], $admin)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '</span>'. '<span style="color:red">' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $moderator)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:green">' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $pc)) { print '<span style="color:gold">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:purple">' . '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . '<span style="color:blue">' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $helper)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:blue">' . '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } elseif (in_array($list['StringyChat_ip'], $globalhelper)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:blue">' . '<b>' . $list['StringyChat_name'] . '</span>' . '<span style="color:green">' . ' ' . '[G.H]' . '</span>' . '</b>' . ' : ' . '<span style="color:blue">' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '</span>' . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } else { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . $form . ' ' . '<span style="color:#0365B8">' . '<b>' . $list['StringyChat_name'] . '</b>' . '</span>' . ' : ' . filterBadWords(wordwrap($list['StringyChat_message'], $line_length,"<br>\n")) . '<span style="color:#d8d8d8">' . " - " . $ipi . '</span>' . '<br />'; } }
This printout will show all the users matching the testip within the admin array, I got the same printout for moderators as well.
Well the real problem I'm experiencing right now is to use my database to calculate the color it should display.
I got 3 tables at this stage
Table 1: Users2
Layout
ID, Username, mxitid, nick, phone and rank
This table is where I store the usernames of people if they register and give them the rank value of 6
Table 2: ranks_colors
Layout
Type, rank, color1, color2, color3, color4
Admin, 1, red, blue, orange, purple
Mod, 2, green, pink, yellow, black
etc... upto 6 wich is Normal
This table is where I specify Type like Administrator rank 1 and 4 colors he can use within hes text printout
Table 3: StringyChat
Layout
id, ip, name, message, time, device, rank
This is basically where the messages that is being send will be stored each in its own row with the specified rank number.
The problem I'm currently struggling with is the ranks I want each rank type font to be different for example in the above Table 2. If admin all the messages send by admin must be red. All the mod messages must be green etc.
How can I change from the array way to mysql by using the ranks system?
-
The back buttons never appear only the forward buttons. the <html> tags has been inserted in the beginning and the end of the script. So I don't think it can be the tags since the part creating the back and forward links are underneath each other nothing in between them as you can see above
Nevermind - I just replaced my code with the original and problem was solved.
-
are the << links present in the 'view source' of the page? i'm guessing that when you are outputting the content on the page, you have some broken html that's eating the links and they are not being rendered correctly. also, according to the program logic, those links don't appear on page 1. do they show up when not on page one?
The back buttons never appear only the forward buttons. the <html> tags has been inserted in the beginning and the end of the script. So I don't think it can be the tags since the part creating the back and forward links are underneath each other nothing in between them as you can see above
-
Hi I'm using the following pagination script, but im having a problem the back to page one "<" and back to previous page "<<" doesn't display only the page forward and and last page work. I can't see my mistake. Any help please.
// find out how many rows are in the table $sql = "SELECT COUNT(*) FROM StringyChat"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 20; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/
-
Test the year diff. This assumes you set the bantime to '9999-12-31' if banned permanently
$expire = $myrow["bantime"]; $dt1 = new DateTime($expire); $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); if ($dif->y > 1000) { // if more than 1000 years $diff = 'PERMANENTLY'; } else { $diff = $dif->format('%m months, %d days, %h hours, %i minutes, %s seconds'); } print $myrow["user"]. " - " . $diff . $banu;
Ah thank you for all the help.
-
No, it wouldn't help much doing it like that. The reason for testing is so you DON'T do a calulation.
while($myrow = mysql_fetch_array($result)) { $ip = mysql_real_escape_string($myrow["ip"]); // WTF is this meant to achieve? $expire = $myrow["bantime"]; if($expire === "PERMANENTLY") { $diff = "Permanently"; print $myrow["user"]. " - " . $diff . $banu; }else{ $dt1 = new DateTime(); $dt1->setTimestamp($expire); // SET TIMESTAMP VALUE (RTFM) $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); $diff = $dif->format('%m months, %d days, %h hours, %i minutes, %s seconds'); print $myrow["user"]. " - " . $diff . $banu; }
Why don't you use a DATETIME field. Then you can set a ban up to '9999-12-31 23:59:59', which is fairly permanent, and won't give you these problems with inconsistent data type in the same field
That could work but how would I go to display Permanent instead of the time lets say if its bigger than 1 year rather display " Permanent" instead of the time when I echo it in the loop??
-
You need to make up your mind whether that column should be a time stamp or not. You seem to want to throw anything into it.
Given what you have you need to check for 'PERMANENT' before you attempt any calculations on the value.
basically I just throw in my time but if its a permanent kick it replaces the the time with the word PERMANENTLY.
What I'm trying to accomplish is to show
username - (Time left on the ban)
but the word Permanent change the outcome
I tried this
$result = mysql_query("SELECT * FROM timeban WHERE `user` != ''",$conn); if($result === FALSE) { die(mysql_error()); // TODO: better error handling } while($myrow = mysql_fetch_array($result)) { $ip = mysql_real_escape_string($myrow["ip"]); $expire = $myrow["bantime"]; if($expire === "PERMANENTLY") { $diff = "Permanently"; $dt1 = new DateTime(); $dt1->setTimestamp($expire); // SET TIMESTAMP VALUE (RTFM) $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); print $myrow["user"]. " - " . $diff . $banu; }else{ $dt1 = new DateTime(); $dt1->setTimestamp($expire); // SET TIMESTAMP VALUE (RTFM) $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); $diff = $dif->format('%m months, %d days, %h hours, %i minutes, %s seconds'); print $myrow["user"]. " - " . $diff . $banu; }
but didn't help
-
Ok on the same topic I have another question
Lets say I kicked a user Permanently and insert into my field bantime the value PERMANENTLY. How can I go to do a while loop but if the one with the word PERMANENTLY appear it should display PERMANENTLY
$result = mysql_query("SELECT * FROM timeban WHERE `user` != ''",$conn);if($result === FALSE) { die(mysql_error()); // TODO: better error handling } while($myrow = mysql_fetch_array($result)) { $ip = mysql_real_escape_string($myrow["ip"]); $expire = $myrow["bantime"]; $dt1 = new DateTime(); $dt1->setTimestamp($expire); // SET TIMESTAMP VALUE (RTFM) $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); echo $myrow["user"]. " - " .$dif->format('%m months, %d days, %h hours, %i minutes, %s seconds') . $banu;
at this moment I get the error
DateTime::setTimestamp() expects parameter 1 to be long, string given in
I know the reason is because it isn't in the right format but thats why I want it to display PERMANENTLY instead of the error in this case.
-
You get 1938 years because you are using a unix timestamp. If you do it that way you need
$dt1 = new DateTime(); $dt1->setTimestamp($expire); // SET TIMESTAMP VALUE (RTFM) $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); echo $dif->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');
ah thank you that solved my problem.
-
Sorry i did not read al of your code but it seems to be more complex then needed.
First about IP-banning.
If you use ip banning instead of user banning please do realise that you could ban a complete officebuilding of hospital ! Otherwise mobile devices are switching ip's many times. I always say: forget this whole IP-shit!
that said,
Did you ever try to use the DateTime and DateInterval standard PHP objects?
<?php $last = new DateTime('2015-1-26 11:53:12'); $now = new DateTime(); $diff = $now->diff($last); echo 'Difference is:<br>'; if($diff->y) echo $diff->y . ' years<br>'; if($diff->m) echo $diff->m . ' months<br>'; if($diff->d) echo $diff->d . ' days<br>'; if($diff->h) echo $diff->h . ' hours<br>'; if($diff->i) echo $diff->i . ' minutes<br>'; if($diff->s) echo $diff->s . ' seconds<br>'; ?>
I use a sort of IP banning because Im running this website as a mobi portal and every user got a unique ID I use as the ip in this case it is
$ip = $_SERVER["HTTP_X_MXIT_USERID_R"];
so that won't be a problem
The problem I'm having seems to be with part 1 the input of the time in my first post.
My database is bantime field is setuped as varchar 30
don't know if it would have any affect
-
1 hour = 3600 seconds.
3600000 seconds, which you are adding, = 41 days 16 hours
And there is an easier way of getting a date difference
$dt1 = new DateTime('2000-01-01'); $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); echo $dif->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds'); // RESULT---> 15 years, 2 months, 2 days, 15 hours, 15 minutes, 15 seconds
Ok I changed
$expire = time() + (3600000 * 1);
to
$expire = time() + (3600 * 1);
and
$expire = $myrowt["bantime"]; $now = time(); echo "You will be unkicked in " . dateDiff($expire, time(), 6) . "<br>";
to
elseif($timet < $myrowt["bantime"]){ $expire = $myrowt["bantime"]; $dt1 = new DateTime($expire); $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); echo $dif->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds'); }
but still it shows
1938 years, 0 months, 0 days, 3 hours, 20 minutes, 6 seconds
and the seconds keep increasing
-
Hi I'm currently having a problem with my time ban option.
Part 1 inserting into database if banned for 1 hour
if($_GET['ban']=='1') { $ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($ip)) { $ip = "Debater"; } $result = mysql_query("SELECT * FROM Users2 WHERE mxitid = \"$ip\""); $row = mysql_fetch_array($result); $name = $row['Username']; $post_time = date("U"); $mxitid = $_GET["ip"]; $user = $_GET["nname"]; $expire = time() + (3600000 * 1); $banby = $name; $banby2 = $_SERVER["HTTP_X_MXIT_USERID_R"]; $IP_To_Remove = $myrow["ip"]; $query = "UPDATE timeban SET user='$user', bantime='$expire', banby='$banby' WHERE mxitid='".$mxitid."'"; mysql_query($query);
Part 2: checking if banned
$ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($ip)) { $ip = "Debater"; } $timet = time(); $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\""; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $sqlt = "SELECT * FROM timeban WHERE mxitid=\"$ip\""; $resultt = mysql_query($sqlt); $myrowt = mysql_fetch_array($resultt); if($resultt === FALSE) { die(mysql_error()); // TODO: better error handling } elseif($timet > $myrowt["bantime"]){ ?> <form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>"> <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20"> <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea> <br> <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message"> </form> <? } elseif($timet < $myrowt["bantime"]){ $expire = $myrowt["bantime"]; $now = time(); echo "You will be unkicked in " . dateDiff($expire, time(), 6) . "\n"; } elseif($myrow["ip"] == "") { // Checks if IP not found in banned list ?> <form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>"> <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20"> <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea> <br> <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message"> </form> <? } else { echo "<span style='color:#10ce59'><u>Dear User, you have been banned from the Chat due to not following the rules. You will need to come back regularly to see if you were unbanned. Until then, goodbye!</u></span><br>"; }
Part 3 Datediff funtion
function dateDiff($time1, $time2, $precision = 6) { // If not numeric then convert texts to unix timestamps if (!is_int($time1)) { $time1 = strtotime($time1); } if (!is_int($time2)) { $time2 = strtotime($time2); } // If time1 is bigger than time2 // Then swap time1 and time2 if ($time1 > $time2) { $ttime = $time1; $time1 = $time2; $time2 = $ttime; } // Set up intervals and diffs arrays $intervals = array('year','month','day','hour','minute','second'); $diffs = array(); // Loop thru all intervals foreach ($intervals as $interval) { // Create temp time from time1 and interval $ttime = strtotime('+1 ' . $interval, $time1); // Set initial values $add = 1; $looped = 0; // Loop until temp time is smaller than time2 while ($time2 >= $ttime) { // Create new temp time from time1 and interval $add++; $ttime = strtotime("+" . $add . " " . $interval, $time1); $looped++; } $time1 = strtotime("+" . $looped . " " . $interval, $time1); $diffs[$interval] = $looped; } $count = 0; $times = array(); // Loop thru all diffs foreach ($diffs as $interval => $value) { // Break if we have needed precission if ($count >= $precision) { break; } // Add value and interval // if value is bigger than 0 if ($value > 0) { // Add s if value is not 1 if ($value != 1) { $interval .= "s"; } // Add value and interval to times array $times[] = $value . " " . $interval; $count++; } } // Return string with times return implode(", ", $times); }
The problem is I banned the user in part 1 for 1 hour but on the output of part 2 it shows up as
You will be unkicked in 45 years, 2 months, 2 days, 13 hours, 13 minutes, 8 secondsand it just keep increasing each time I refresh instead of decreasing
-
Here's a bit of code from my client login page. It works.
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // First brace if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Letters and numerals only"; } } } // Last brace ?>
Ok seems like this solved my problem, just one last question how would I go if I would like to allow one space between words like for example "Jon Snow"
-
try
if(empty(trim($_POST['formName'])))
I tried it but got an error
Here is my current code.
<?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty(trim($_POST['formName']))) { $errorMessage .= "<li>You forgot to enter a name!</li>"; } $varName = trim($_POST['formName']); $nick = urldecode($_SERVER['HTTP_X_MXIT_NICK']); $phone = urldecode($_SERVER["HTTP_X_DEVICE_USER_AGENT"]); $ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($phone)) { $phone = "Other"; } if(!isset($ip)) { $ip = "Debater"; } if(empty($errorMessage)) { $db = mysql_connect("********","*******","***********"); if(!$db) die("Error connecting to MySQL database."); mysql_select_db("*******" ,$db); $sql = "INSERT INTO Users2 (Username, mxitid, nick, phone) VALUES (" . PrepSQL($varName) . ", ". PrepSQL($ip) . ", " . PrepSQL($nick) . ", " . PrepSQL($phone) . ")"; mysql_query($sql); header("Location: thankyou.html"); exit(); } } // function: PrepSQL() // use stripslashes and mysql_real_escape_string PHP functions // to sanitize a string for use in an SQL query // // also puts single quotes around the string // function PrepSQL($value) { // Stripslashes if(get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote $value = "'" . mysql_real_escape_string($value) . "'"; return($value); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>PHP Form processing example</title> <!-- define some style elements--> <style> label,a { font-family : Arial, Helvetica, sans-serif; font-size : 12px; } </style> </head> <body> <?php if(!empty($errorMessage)) { echo("<p>There was an error with your form:</p>\n"); echo("<ul>" . $errorMessage . "</ul>\n"); } ?> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <p> <label for='formName'>What is your name?</label><br/> <input type="text" name="formName" maxlength="50" value="<?=$varName;?>" /> </p> <input type="submit" name="formSubmit" value="Submit" /> </form> </body> </html>
-
Hi I'm currently developing a register page within my form I want the user to specify a name. The problem I curently have is when a user press the spacebar and submit hes name it gets accepted.
<?php if($_POST['formSubmit'] == "Submit") { $errorMessage = ""; if(empty($_POST['formName'])) { $errorMessage .= "<li>You forgot to enter a name!</li>"; } if($_POST['formName'] == " ") { $errorMessage = "<li>You cant insert an empty field!</li>"; } $varName = trim($_POST['formName']); $nick = urldecode($_SERVER['HTTP_X_MXIT_NICK']); $phone = urldecode($_SERVER["HTTP_X_DEVICE_USER_AGENT"]); $ip = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($phone)) { $phone = "Other"; } if(!isset($ip)) { $ip = "Debater"; } if(empty($errorMessage)) { $db = mysql_connect("***********","******","*****"); if(!$db) die("Error connecting to MySQL database."); mysql_select_db("********" ,$db); $sql = "INSERT INTO Users2 (Username, mxitid, nick, phone) VALUES (" . PrepSQL($varName) . ", ". PrepSQL($ip) . ", " . PrepSQL($nick) . ", " . PrepSQL($phone) . ")"; mysql_query($sql); header("Location: thankyou.html"); exit(); } } // function: PrepSQL() // use stripslashes and mysql_real_escape_string PHP functions // to sanitize a string for use in an SQL query // // also puts single quotes around the string // function PrepSQL($value) { // Stripslashes if(get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote $value = "'" . mysql_real_escape_string($value) . "'"; return($value); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>PHP Form processing example</title> <!-- define some style elements--> <style> label,a { font-family : Arial, Helvetica, sans-serif; font-size : 12px; } </style> </head> <body> <?php if(!empty($errorMessage)) { echo("<p>There was an error with your form:</p>\n"); echo("<ul>" . $errorMessage . "</ul>\n"); } ?> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <p> <label for='formName'>What is your name?</label><br/> <input type="text" name="formName" maxlength="50" value="<?=$varName;?>" /> </p> <input type="submit" name="formSubmit" value="Submit" /> </form> <p> <a href='http://www.html-form-guide.com/php-form/php-form-processing.html' >'PHP form processing' article page</a> </p> </body> </html>
As you can see I added
if($_POST['formName'] == " ") { $errorMessage = "<li>You cant insert an empty field!</li>"; }
This works if the person only typed a whitespace(spacebar) once but if the person types it more then once it gets accepted again. Any help?
-
LOL join is exactly the same function as implode()
well it works with implode but not join weird hey
-
It will if you use a for(each)/while loop?
$badnames = ('Admin','Admin2','Admin3'); $name2 = 'Nice try'; $name = ...; foreach($badnames as $word) { if (false !== stripos($name,$word)) { $name = $name2; break; } }
Ah thank you
Do you want to match actual WORDS? Or just see if a string is located within a string? If it's the first one, you don't want to use stripos() as it will do the 2nd one.
Like if you want to search for "admin", stripos() would find it in:
"let's readminister the medicine"
"administrative assistant"
etc.
Yes I'm aware of it, Basically I want to use this option to block users from using any name with the specific words inside their name.
Upload resize and convert images turn black help
in PHP Coding Help
Posted
Hi I have 3 files
profilepicf.php
profilepic_new.php
ak_php_img_lib_1.0.php
The problem I'm currently experiencing is when I try to upload PNG files, I get a black image and an error message while uploading it
Any help related to this problem please