Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Apache/PHP Integration
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
no1youknowz  
View profile  
 More options Nov 26 2010, 8:31 pm
From: no1youknowz <no1youkn...@gmail.com>
Date: Fri, 26 Nov 2010 17:31:48 -0800 (PST)
Local: Fri, Nov 26 2010 8:31 pm
Subject: Apache/PHP Integration
Hopefully this helps those running Apache/PHP.

If there are any questions, I'll try to answer them.  Before asking
questions, please do a search on google as a lot of the answers can be
found there.

1) Download latest NodeJS (0.3.1): http://nodejs.org/dist/node-v0.3.1.tar.gz

2) Check out the install instructions for AJAXIM here:
http://groups.google.com/group/ajaxim/msg/7e215574c7e9573a

3) Ensure that you can hit http://localhost:8000/dev/ and that AJAXIM
is working before proceeding!

4) Insert into your Apache configuration into the V-Hosts directive:

Proxypass /chat http://localhost:8000

Here is an example:

<VirtualHost *:80>
    ServerAdmin admin@[domain.tld]
    DocumentRoot /var/www/html/[websitedir]
    ServerName [domain.tld]
    ServerAlias [domain.tld] *.[domain.tld]

    Proxypass /chat http://localhost:8000
    ProxyTimeout 310
</VirtualHost>

* Note that [websitedir] is the folder of where your website resides
* [domain.tld] is the website, e.g google.com
* For the proxypass line: localhost and 8000 should reflect where your
NodeJS settings (if changed from the default)

5) Integrate the below into your front controller:

<script src="/js/md5.js" type="text/javascript"></script>
<script src="/js/store.js" type="text/javascript"></script>
<script src="/js/cookies.js" type="text/javascript"></script>
<script src="/js/dateformat.js" type="text/javascript"></script>
<script src="/js/im.js" type="text/javascript"></script>

<script type="text/javascript">
$(function(){
        var im = AjaxIM.init({
                theme: "/modules/ajaxim/themes/default",
                pollServer: "http://www.domain.tld/chat"
        });

});

</script>

* Note that domain.tld should reflect the website.

6) Custom htaccess rules

Insert these 2 rules into your htaccess file which should reside in
the basedir of your website

# --- AjaxIM ---
RewriteRule ^ajaxim/getuser$            /directory/getuser.php [L]
RewriteRule ^ajaxim/getfriends$         /directory/getfriends.php [L]

* Note that directory should be a directory like ajaxim that exists in
your basedir and holds the 2 files getuser.php and getfriends.php
* [L] is a flag that means that when Apache processes the rules then
it stops processing the htaccess file.

7) getuser.php

Here is an example script to retrieve the username from the session
id.  I have my own custom backend and your backend will be different.

The point is that I generate a JSON string that is outputted for the
consumption of NodeJS.

<?php

$sessionid = $_COOKIE['sessionid'];
$sql = "select username from users where sessionid = '$sessionid';";
$result = $dbconn->fetchRow($sql, PDO::FETCH_ASSOC);

$username = $result[0]['username'];

echo '{"username":"' . $username . '"}';

?>

8) getfriends.php

<?php
$arr = array ('friend1', 'friend2', 'friend3');
echo json_encode($arr);
?>

Same principle as the above except that it outputs:

["friend1","friend2","friend3"]

9) See post from Joshua about Authentication:
http://groups.google.com/group/ajaxim/msg/7ae5ab0b6164926c

10) Custom index.js

* Note that ajaxim/ matches up with the .htaccess ruleset.

// Cookie that stores the session ID
// Will be set as request.sessionID in `authenticate` and `friends`
functions
exports.cookie = 'sessionid';

exports.authenticate = function(request, callback) {
        var http = require('http');
        var site = http.createClient(80, 'localhost');
        var req = site.request('GET', '/ajaxim/getuser', {
                host: 'www.domain.tld',
                cookie: exports.cookie + '=' + request.sessionID
   });
        req.end();
        req.on('response', function (response) {
                var data = '';
                response.setEncoding('utf8');
                response.on('data', function(chunk) {
                        data += chunk;
                });

                //console.log (request.sessionID);

                response.on('end', function() {
                        try {
                                callback(JSON.parse(data));
                        } catch(e) {
                                callback();
                        }
                });
        });

};

exports.friends = function(request, data, callback) {
        var http = require('http');
        var site = http.createClient(80, 'localhost');
        req = site.request('GET', '/ajaxim/getfriends', {
                host: 'www.domain.tld',
                cookie: exports.cookie + '=' + request.sessionID
        });

        req.end();
        req.on('response', function(response) {
                var data = '';
                response.setEncoding('utf8');
                response.on('data', function(chunk) {
                        data += chunk;
                });
                response.on('end', function() {
                        try {
                                callback(JSON.parse(data));
                        } catch(e) {
                                callback();
                        }
                });
        });

};

11) That's.  I would really put logic in point 5) that it only shows
up when there is a valid session, i.e the user has authenticated.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »