How do I automatically login to another database from a current website in cakephp

In cakephp I can login to a website no problem.
What I need to do is login and then click a button that will send me another cakephp website with its own login.
This works fine (on my pc) but I I need to automatically login to the website without having to login again

 echo $this->Html->link( 'link!', 'http://127.0.0.1/maths/numeracyStudents/dashboardst');
jagguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
You use Curl and cookies.  Store the cookie on your server and reuse it to log into the other site as needed.

So in your controller, is there a specific action that initiates this?
?
0
Loganathan NatarajanLAMP DeveloperCommented:
0
RobOwner (Aidellio)Commented:
Logan,

How does your solution cover this part?:
What I need to do is login and then click a button that will send me another cakephp website with its own login.

The server needs to make the connection to the other site, not the client
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

jagguyAuthor Commented:
Hi,
Thanks for the replies
Without an example in cakephp I cant spend hours fiddling and hoping something will work.
This either can be done or it cant. If it can can someone point me to an example please.
0
RobOwner (Aidellio)Commented:
Of course it can be done but how I've done it may not work for your implementation.

I have a class I've called proxy that handles all the CURL calls. It maintains the cookies etc.

I'll post the code of that class soon when I'm at my laptop
0
RobOwner (Aidellio)Commented:
<?php

class SiteProxy {

    function __construct($session) {
        $this->base_url = "http://www.domain.com/"; #trailing slash
        $this->Session = $session;

        $this->curl = curl_init();
        $session->check('non.existant'); #init the session so it has an ID
        $cookie_file_path = realpath("../cookies/") . "/site_" . $session->id();
        curl_setopt_array($this->curl, array(
            CURLOPT_COOKIEFILE => $cookie_file_path,
            CURLOPT_COOKIEJAR => $cookie_file_path,
            CURLOPT_FOLLOWLOCATION => True,
            CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7',
        ));
    }

    function __destruct() {
        @curl_close($this->curl);
    }

    /*
      1)Don't use CURLOPT_FOLLOWLOCATION
      2)Use curl_setopt($ch, CURLOPT_HEADER, 1)
      3)Grab from the header cookies like this:
      preg_match_all('|Set-Cookie: (.*);|U', $content, $results);
      $cookies = implode(';', $results[1]);
      4)Set them using curl_setopt($ch, CURLOPT_COOKIE,  $cookies);
     */

    function fetch_url($url, $method = "GET", $data = '', $follow = true) {
        //echo 'Requesting '.$url.' with '.$method.' and parameters '.$data;
        $ch = $this->curl;
        curl_setopt($ch, CURLOPT_URL, $url);
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        } else {
            curl_setopt($ch, CURLOPT_HTTPGET, true);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // true: return contents as a string, false: output to browser
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow);

        $thePage = curl_exec($ch);
        unset($ch);
        return $thePage;
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Loganathan NatarajanLAMP DeveloperCommented:
The server needs to make the connection to the other site, not the client


In the first website, i login and store the details using cookie and retrieve in second website on the first page.
0
RobOwner (Aidellio)Commented:
Can you show a code example?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.