Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:42:48+00:00 2026-05-31T06:42:48+00:00

I have an app which allows users to log in via Facebook, and all

  • 0

I have an app which allows users to log in via Facebook, and all users who have registered have their Facebook ID stored in our database so that we know who has and who hasn’t registered our app. Very standard stuff, and that part all works fine and has been tested etc.

Next I need to let users see which of their friends already have the app (i.e. which ones have registered).

I get their friends list from Facebook, make a JSON string of all of their user IDs and now I need to know how to send this JSON string to my PHP script and have it compare the JSON to all of the users in the database already and create an array of ID’s which are found in both the JSON string and the DB.
I then need to send that array back to the app via PHP (presumably as a JSON again) so that I can filter out the non-registered ID’s from the users list of Facebook friends.

To register the user I am currently using the following format in the app to send requests:

NSString *host = @"my.domain";
NSString *urlString = [@"myPHP.php?"stringByAppendingString:@"task=register"];
//list of args which are sent
NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:host path:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSError *requestError = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&requestError];

In my PHP I use something along these lines (I’ll leave out the parts where I connect to the DB etc, as that all works and I imagine is standard for all applications):

function __construct($db, $args=NULL) {
    $this->db = $db;
    $this->checkSetup();
    $this->apnsData = array(
        'production'=>array(
            'certificate'=>$this->certificate,
            'ssl'=>$this->ssl,
            'feedback'=>$this->feedback
        ),
        'sandbox'=>array(
            'certificate'=>$this->sandboxCertificate,
            'ssl'=>$this->sandboxSsl,
            'feedback'=>$this->sandboxFeedback
        )
    );
    if(!empty($args)){
        switch($args['task']){
            case "register":
                $this->_registerDevice(
                    $args['appname'],
                    $args['devicetoken'],
                    $args['facebookID']
                );
                break;
                //etc

As I say this all works fine, and I use something similar for another function. However these are both functions which do not require anything to be sent back to the app itself, so I would be very appreciative of any help here on what to do next.

To sum up what I’m stuck on:

  • Sending a JSON string to PHP script.
  • Comparing said JSON to an array containing all entries from one column in a mySQLi DB.
  • Returning an array of matching entries back to the app.

I’d be grateful for any help anyone can give as I have done very little work with PHP or mySQL in the past and so I’m not sure where to go next.

Thanks Everyone 🙂

Edit: I’ve just tried making a fake URL request to run in the browser, just to see what happens when I send a JSON string to the PHP code (I just have it echo the result). I get a 414 error (the URI is too long). Does this mean that this would not be a suitable method for retrieving the results I want? I have around 200 friends’ IDs in the JSON string, but many people would have far more than that.

Edit 2: Further to the comments that have been left, would something like this be a more appropriate way of sending the data:

NSString *jsonString = [friendsIDArray JSONRepresentation];
NSMutableURLRequest *mrequest = [[NSMutableURLRequest alloc] init];
NSString *post = [NSString stringWithFormat:@"json=%@", jsonString];
NSLog(post);


NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];

[mrequest setURL:[NSURL URLWithString:@"http://plantpot.co/app_Boom_php/apns.php"]];
[mrequest setHTTPMethod:@"POST"];

[mrequest setHTTPBody:postData];

[[NSURLConnection alloc] initWithRequest:mrequest delegate:self];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:42:49+00:00Added an answer on May 31, 2026 at 6:42 am

    Managed to get it working using GET in the end.

    NSString *jsonString = [friendsIDArray JSONRepresentation];
    
    //send this to the server
    NSString *friendHost = @"ourdomain.com";
    NSString *friendurlString = [@"/thephp.php?"stringByAppendingString:@"task=getRegistered&jsonList=%@", jsonString];
    NSURL *friendURL = [[NSURL alloc] initWithScheme:@"http" host:friendHost path:friendurlString];
    NSURLRequest *friendRequest = [[NSURLRequest alloc] initWithURL:friendURL];
    NSError *friendRequestError = nil;
    
    //the reply is the list of ID's which are NOT registered on the database
    NSData *friendReturnData = [NSURLConnection sendSynchronousRequest:friendRequest returningResponse:nil error:&friendRequestError];
    
    NSString *stringReply = (NSString *)[[NSString alloc] initWithData:friendReturnData encoding:NSUTF8StringEncoding];
    
    //convert this string to an array
    NSArray *unregisteredFriends = [stringReply JSONValue];
    

    Then in the PHP script I did the following:

    function _returnRegisteredFriends($jsonArg)
    {
    
        $db = new DbConnect();
        $column = array();
        $result = $db->query("SELECT facebookID FROM registered_users");
    
        //populate column array with all of the facebook user IDs
        while($row = $result->fetch_array(MYSQLI_ASSOC)){
            $column[] = $row['facebookID'];
        }
    
    
        $newphrase = str_replace('\\', '', $jsonArg);//remove escape characters
        $decoded = json_decode($newphrase);//from json to array
        $arrayresult = array_diff($decoded, $column);
        echo json_encode($arrayresult);
    }
    

    This gets all of the users ID’s from my database, and compares it to an array passed through to it ($jsonArg). The difference is then worked out and then the echo returns it back to the app as the friendReturnData.

    All seems to be working as it should, thanks to the guys who suggested using the POST method – just turned out that the GET method was satisfactory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have a Rails app which allows users to upload Excel files which need
We have an ASP.NET MVC web app which allows users to publish messages onto
I'm currently working on my first Django app, which allows registered users to submit
I have a fairly simple site which allow users to connect via facebook. I
I have written my cake app to log in registered users and it works
I have an app which allows users to vote and have two tables Video
I am developing an app which allows users to color the images. I have
I have a flex app which allows user to create some content. this content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.