Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Any facebook app developers out there?

Options
  • 03-08-2008 6:29pm
    #1
    Registered Users Posts: 3,370 ✭✭✭


    Hi,
    I'm slowly starting to develop an app for http://www.ratemypub.ie, I've gotten hello world working and I have an idea of what I want to do, users select their fave pubs and add when they're out next and where etc.
    Would love to meet some fella here that would give me a bit of a tute?
    Anyways my problem at the moment is what do I do to register the users?

    I have an app (in the background of ratemypub) where you register using your name, email etc and then you can go in and pick your pubs etc etc

    I'm wondering how do I link the facebook app to this? Do I just redirect the user to ratemypub when he accepts my app or is there a way of linking the two??

    Thanks for any advice ye can give me, hope everyone's enjoying the long weekend.

    Gary


Comments

  • Registered Users Posts: 3,140 ✭✭✭ocallagh


    yep, been developing apps for about 6 months now. It's really quite easy to get a basic site up and running.

    This is a generic response - but to link user data with a user in facebook, simply put a reference to the users Facebook ID (which you can get using API - see below) in your database


    First - Add the Developer Application and create a new Application (you will get an API Key and a Secret API Key but for now these are not important). You will also setup your applications Canvas page. For this example I will use http://apps.facebook.com/helloworld/

    Make sure to set FBML as the App Type for this example.

    You should also setup a Callback URL. This is the URL Facebook servers will use to grab content when a user makes a request to your app. For this example I will use http://www.yourserver.com/facebook/. You need a server which FB can reach, ie: not localhost.

    So, on your server in the /facebook/index.php page you need to write some code. don't output HTML, rather a subset of HTML called FBML. Most HTML tags are valid FBML except for HTML, HEAD, BODY etc. So for example, index.php could be as simple as
    <h2>Hello World</h2>
    
    You can then start mixing in some FB speficic tags like
    <fb:name uid="12345678"/>
    
    which will output the name of user ID 12345678. How (and where) you get that ID I will get to later. For a user comment wall you use
    <fb:comments/>
    
    etc etc. FB Tags are very useful and a full list of them can be found here: http://wiki.developers.facebook.com/index.php/FBML

    So your page could look like:
    <h2>Hello <fb:name uid="12345678"/></h2>
    <p>Leave a comment</p>
    <div id="comments">
    <fb:comments xid="hellow_world_comments" canpost="true" candelete="false" returnurl="http://apps.facebook.com/helloworld/index.php?comment_posted=1"/>
    </div>
    
    For multiple pages, FB simply maps the folders. So, if someone types in http://apps.facebook.com/helloworld/sport/index.php FB will (via HTTP request) attempt to grab FBML from http://www.yourserver.com/facebook/sport/index.php

    So the whole exchange of data works like this

    1) Facebook User goes to Your App (http://apps.facebook.com/helloworld/)
    2) Facebook Server requests FBML from Your Server (http://www.yourserver.com/facebook/ )
    3) Your Server returns FBML to Facebook Server
    4) Facebook Server renders FBML into HTML and returns to Facebook User

    SO, that's the basics out of the way. Next for API calls

    In addition to FB just requesting FBML from your server, your php files can request data from FB before it sends the FBML back. This data is fetched via API calls to the FB REST Server and can be used to populate USER IDs for the FBML etc. So, now the exchange of data looks like this

    1) Facebook User goes to Your App (http://apps.facebook.com/helloworld/)
    2) Facebook Server requests FBML from Your Server (http://www.yourserver.com/facebook/ )
    3) Your Server requests Data from Facebook API Server
    4) Facebook API Server send data to Your Server
    5) Your Server renders this data (JSON or XML) and uses it to generate FBML
    6) Your Server sends the FBML back to Facebook (In response to #2 - Facebooks initial request)
    6) Facebook Server renders FBML into HTML and returns to Facebook User

    To use the API REST Server you need to specify the IP addresses of your servers making the request (done within Developer Application).

    You then need to grant your PHP file access to use the API REST Server. This involves logging in to FB with your API Key and Secret Key (via API). The login process is simple, and provided you use the Facebook Libraries it can be as simple as (in PHP)
    <?php
    include("/lib/facebook.php");
    $facebook = new Facebook($api_key, $secret_key);
    ?>
    
    In the background your PHP file will authenticate with Facebook and create a session for future requests.

    Interacting with Users
    TO request a user adds or logs into your app when they visit (so you can interact with them) you call the require_login() method which will redirect the user to the Login/Add page, and once completed will send them back to your app with the appropriate cookies/session set

    You can make API calls and FQL (subset of SQL) to grab info. FQL returns associative arrays

    So, your PHP file could look like this (I might have some of the FQL wrong!)
    <?php
    include("/lib/facebook.php");
    $facebook = new Facebook($api_key, $secret_key);
    $facebook->require_login();
    $user=$facebook->get_loggedin_user();
    
    //Some FQL
    $query = "SELECT current_location FROM user WHERE uid =" . $user;
    $result = $facebook->api_client->fql_query($query);
    
    ?>
    <h2>Hello <fb:name uid="<?=$user?>"/> you are from <?=$result[0]["current_location"]["city"]?></h2>
    
    There is tonnes you can do with FQL/API/FBJS and FBML - and I didn't even touch on the API Data Store - for more info http://wiki.developers.facebook.com


  • Registered Users Posts: 3,370 ✭✭✭randombar


    Thanks very much ocallaigh, that was really good to get my head around what was going on (Especially the FQL part)

    A couple of questions I would have would be:

    Am I better off having the user registered to my site through facebook or should I direct them from facebook to my site to do the registering and picking of favorite pubs, (obviously easier coding wise for me to send em to my site but I don't think that's the norm in face book apps)

    If I'm to do it all via facebook is it easy to set up submission forms and the likes? i.e. I'd like the user to select their tops pubs from a drop down list etc.

    Thanks again for your help, let me know what apps you've developed and I'd definitely add them!


  • Registered Users Posts: 3,140 ✭✭✭ocallagh


    GaryCocs wrote: »
    Thanks very much ocallaigh, that was really good to get my head around what was going on (Especially the FQL part)

    A couple of questions I would have would be:

    Am I better off having the user registered to my site through facebook or should I direct them from facebook to my site to do the registering and picking of favorite pubs, (obviously easier coding wise for me to send em to my site but I don't think that's the norm in face book apps)

    If I'm to do it all via facebook is it easy to set up submission forms and the likes? i.e. I'd like the user to select their tops pubs from a drop down list etc.

    Thanks again for your help, let me know what apps you've developed and I'd definitely add them!
    I'm working on a bit of a project of my own here: http://apps.new.facebook.com/fantasyteamslive/index.php - not too many users but it's growing steadily (another very similar app hogs them all :()


    In regards user registration, why not do them on both Facebook and your site!! That's what I do with the site above. I have one user table for users from both sites. The main columns in the Users table are as follows

    UserId | Username | Password | Email | IsFacebook | FacebookId

    For logging in, if it's through my own site I get them to log in regularly with Username/Password Combo. If it's through Facebook I authenticate using the Facebook authentication process (The Password field for Facebook users is set to random, and is never used). If it's their first time on my app, I just auto register them. If you want to grab more details off them you could ask them at any stage.

    The following I just wrote up now, and haven't checked anything but the syntax, but in theory it should work.

    This could be a loginscript.php file which you include at the top of each page on your site. If the Server Name starts with facebook.com, set the $site variable to "facebook"
    [LEFT][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]<?php[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
     
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]global [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$facebook[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//Make this global so we can use it throughout the site[/COLOR][/SIZE][/COLOR][/SIZE]
     
     
    
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$UserAccess [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][LEFT][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$UserId[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=null;[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= mysql_connect([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"host"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"username"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"password"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/LEFT]
    [SIZE=2]mysql_select_db([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"Pubs"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$site[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]==[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"facebook"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//we're on facebook, so we need to do this each time the page loads[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"/lib/facebook.php"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$facebook [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]Facebook([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$api_key[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$secret_key[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//***** NB ***** For Session ID, Facebook expects an [/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//MD5 hash of the users FB session key (FB stores this)[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]// SO force the app to use that session ID[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$session_key [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= md5([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$facebook[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]->api_client->session_key);[/SIZE]
    [SIZE=2]session_id([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$session_key[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2]session_start();[/SIZE]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//*** end of crap!![/COLOR][/SIZE][/COLOR][/SIZE]
     
    [LEFT][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$facebook[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]->require_login();[/SIZE][/LEFT]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$user[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$facebook[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]->get_loggedin_user();[/SIZE]
     
    [LEFT][SIZE=2]}[/SIZE][/LEFT]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//Just start the session normally for your own site[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]session_start();[/SIZE]
    [SIZE=2]}[/SIZE]
     
     
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//If they are not logged in already[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](![/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"Authenticated"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]))[/SIZE]
    [LEFT][SIZE=2]{[/SIZE][/LEFT]
     
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]/**********************************************************************[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]* FACEBOOK[/COLOR][/SIZE]
    [SIZE=2][COLOR=#808080]*/[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$site[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]==[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"facebook"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) {[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//If we get this far, we can be sure that the ID stored in $user is authenticated[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//So either do an INSERT or a SELECT on the User table[/COLOR][/SIZE][/COLOR][/SIZE]
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//My own DB Query[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$results [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= mysql_query([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"select UserId from Users where FacebookId = " [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]. [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$user [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]. [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]" LIMIT 1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](mysql_num_rows([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$results[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) > [/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE][/LEFT]
    [SIZE=2]{ [/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $user_row [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= mysql_fetch_row([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$results[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $UserId [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$user_row[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"UserId"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"Authenticated"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"UserId"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$UserId[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//FB Query[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $query [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"SELECT name FROM user WHERE uid =" [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]. [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$user[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $result [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$facebook[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]->api_client->fql_query([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$query[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [LEFT][SIZE=2]   mysql_query([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"INSERT INTO Users Set Username='"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$result[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"name"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]].[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"', IsFacebook=1, FacebookId="[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$user[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/LEFT]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $UserId [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= mysql_insert_id([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"Authenticated"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"UserId"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$UserId[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"Registered"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//If you want to give them a welcome message or something[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2]}[/SIZE]
     
    [LEFT][SIZE=2]}[/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]/**********************************************************************[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]* YOUR SITE[/COLOR][/SIZE]
    [SIZE=2][COLOR=#808080]*/[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//We are on our own site, so must authenticate ourselves[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2]{[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//Grab the values from the Form (if one was submitted)[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$username [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]isset[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$_GET[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"username"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]) ? addslashes([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$_GET[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"username"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]) : [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$password [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]isset[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$_GET[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"password"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]) ? addslashes([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$_GET[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"password"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]) : [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
     
     
    [LEFT][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](![/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]empty[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$username[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) && ![/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]empty[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$password[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]))[/SIZE][/LEFT]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//My own DB Query[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]  $results [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= mysql_query([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"select UserId from Users where Username='"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$username[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"' and Password = '"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$password[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"'"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [LEFT][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]   if [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](mysql_num_rows([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$results[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) > [/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE][/LEFT]
    [SIZE=2]  {[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]    $user_row [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= mysql_fetch_row([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$results[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$conn[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]    $UserId [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$user_row[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"UserId"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]    $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"Authenticated"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]    $_SESSION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"UserId"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$UserId[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]   }[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]   else[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2]   {[/SIZE]
    [SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]       //redirect to forgotpassword[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2]       header([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"location: forgotpassword.php"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [SIZE=2]   }[/SIZE]
    [SIZE=2]}[/SIZE]
     
    [LEFT][SIZE=2]}[/SIZE][/LEFT]
    [SIZE=2]}[/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]//End check[/COLOR][/SIZE][/COLOR][/SIZE]
     
    [SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]?>[/COLOR][/SIZE]
    [/COLOR][/SIZE]
     
    
    [/LEFT]
    
     
     
    
    



    So then other pages on your site could look like this

     
    [SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000][LEFT]<?php[/LEFT]
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][LEFT]include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"loginscript.php"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/LEFT]
    [/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000][LEFT]$TemplateDirectory [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= ([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$site[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]==[/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"facebook"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) ? [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"/mysite/" [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]: [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"/facebook/"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    [/LEFT]
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][LEFT]include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$TemplateDirectory [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]. [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"header.inc.php"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    [/LEFT]
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][LEFT]echo [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"<h2>Hello!</h2>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/LEFT]
    [/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080][LEFT]//display any forms here etc[/LEFT]
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][LEFT]include[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#660000][SIZE=2][COLOR=#660000]$TemplateDirectory [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]. [/SIZE][SIZE=2][COLOR=#008200][SIZE=2][COLOR=#008200]"footer.inc.php"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    [/LEFT]
    [/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]?>
    [/COLOR][/SIZE][/COLOR][/SIZE] 
    

    Of course, if both your site and your facebook app are going to be different you should split up the codebase.


  • Registered Users Posts: 3,140 ✭✭✭ocallagh


    oh, and for images and CSS for facebook they must be absolute URLS

    For all that kind of stuff including submission forms, I just store a $baseurl variable which is either http://www.mysite.com or http://apps.facebook.com/myapp

    and then, for forms etc I use <form action="<?=$baseurl?>/folder/filename.php">


  • Registered Users Posts: 3,370 ✭✭✭randombar


    Nice one for that ocallagh, I've signed myself up for the app, invited all the lads.

    Gonna have a proper crack off this stuff myself now over the weekend!

    Gary


  • Advertisement
  • Registered Users Posts: 3,370 ✭✭✭randombar


    So making my way through this all right, just wondering how do you link form page to page?

    Is your canvas page directing to homesite.com/facebook/index.php?

    I have this set up but for some reason my links direct to index.php?pub.php?info= . . . .


Advertisement