Login integration for 2 different 3rd party scripts in PHP

Posted on 2008-11-19
Last Modified: 2012-05-05
Hi, I am trying to create a bridge between two different scripts. One is textpattern for news/blog and another one is a social networking script (SNS). When a user creates an account in textpattern or SNS, I know that it should automatically create a clone account to the other script. But I would like to if a user logs into textpattern, how can I let it login to SNS too? Is there some kind of HTML header command that will do that automatically?

I don't want to create a whole new user session tracking routine for both, because I think that is going to be a huge work from scratch. Thank you.
Question by:santocki
    LVL 9

    Expert Comment

    It should be possible to do..

    First of all, this was very confusing to me, I am assuming that you have 2 applications:
    Social Networking Script
    Textpattern CMS

    You have both of these scripts combined in one website. You would like to allow a user to log into the website once, however each script requires a separate login by default.

    Do each of these scripts require separate registration as well? I would assume so, and if you do not plan to connect the registration process I advise against merging the sign in process as there could easily be complications (different credentials).

    If you just wanted to sign in to both accounts at once by a single page, examine the login protocol for each script. Do they require $_REQUEST data? Do they use this data in a function call? Since we are missing the 2 login pages, I will post 2 example login pages and let you fill in the blanks.

    If this is the case, simply require() the needed scripts and call the 2 functions on a single page. Hopefully there are no conflicts and it's that simple.
    // SNS Login.php
    $username = $_POST['username'];
    $password = $_POST['password'];
    if (doLogin($username, $password)){
    // textpattern Login.php
    $uname = $_GET['txtUsername'];
    $pword = $_GET['txtPassword'];
    if (login_user($uname, $pword)){
    // Merged login.php
    $usrname = $_REQUEST['your_username_field'];
    $passwd  = $_REQUEST['your_password_field'];
    if (login_user($usrname, $passwd) && doLogin($usrname, $passwd)){ 
       echo "login failed!";
    Obviously, this is dependent on the third party applications login protocol. Likely it is NOT that simple. You will have to figure out how they do it, and find a compatible way if running them both at the same time. There's a good chance they either use cookies or sessions to store the validity of the user. Good luck!

    Open in new window


    Author Comment

    Thank you for the response. But it is not exactly what I needed. What I need to know is:

     I would like to send HTTP header codes to the second application's login page so it will be logged in, as if the user have inputted the username and the password via <FORM> tag (more like a bot logging in automatically for me, but all this happens in the background, so user will NOT be redirected to the second application). I don't want to use PHP's header() function.  This way, I don't have to include any functions from the second application (either SNS or Textpattern CMS). Is this even possible? Hope it makes sense.

    Thank you.

    Author Comment

    Adding to the previous comment...

    I have a Contact Form on my site and everyday I get the form message submitted by spam bots automatically. I am trying to make it work similar like that by sending user's username, password and IP info (the IP info means not sending a string, but it should be captured by $_SERVER['REMOTE_ADDR'] variable as if the visitor has physically visited the page for logging in ). Thank you.
    LVL 9

    Accepted Solution

    Ah I see, you can use curl for this. I don't have time to go over usage in detail right now, but I'll link you to a reference I've used in the past.

    Good luck!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now