SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Login through different sites?

    I have a form(myform.php) on Server A that can only be accessed after attaining the correct session cookie from logging in from the log in page(login.php). So naturally the form can only be submitted if I am logged in.

    And now, is it possible from Server B, to have a script to log in through login.php to attain the session cookie on the server and then do a submit in the myform.php?

    So in another words, I need Server B to act as me logging into login.php and submitting the form on Server A.

  2. #2
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That might be a security violation. I don't think that possible and if so would probably require you to read from server A, which if secure causes a problem, or have your code copy the cookie and place in a variable that server b can just read and replace.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it's quite possible.
    You could search for php curl login to find more info.

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by x[E]nOn View Post
    I have a form(myform.php) on Server A that can only be accessed after attaining the correct session cookie from logging in from the log in page(login.php). So naturally the form can only be submitted if I am logged in.

    And now, is it possible from Server B, to have a script to log in through login.php to attain the session cookie on the server and then do a submit in the myform.php?

    So in another words, I need Server B to act as me logging into login.php and submitting the form on Server A.
    Sure, it's pretty trivial using a PHP HTTP Client.

    Here's an example from Zend_Http_Client:
    PHP Code:
    $client = new Zend_Http_Client();

    // To turn cookie stickiness on, set a Cookie Jar
    $client->setCookieJar();

    // First request: log in and start a session
    $client->setUri('http://example.com/login.php');
    $client->setParameterPost('user''h4x0r');
    $client->setParameterPost('password''1337');
    $client->request('POST');

    // The Cookie Jar automatically stores the cookies set
    // in the response, like a session ID cookie.

    // Now we can send our next request - the stored cookies
    // will be automatically sent.
    $client->setUri('http://example.com/read_member_news.php');
    $client->request('GET'); 
    Zend_Http
    PEAR\HTTP_Client
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a form(myform.php) on Server A that can only be accessed after attaining the correct session cookie from logging in from the log in page(login.php). So naturally the form can only be submitted if I am logged in.

    And now, is it possible from Server B, to have a script to log in through login.php to attain the session cookie on the server and then do a submit in the myform.php?

    So in another words, I need Server B to act as me logging into login.php and submitting the form on Server A.




    Yes...Ofcourse, it's Possible.

    Try using PHP CURL



    Try to get some idea from the following code and try to implement it as per your need

    PHP Code:
    <?php
    $url 
    ="http://www.yoursite.com/login.php";
    $ch curl_init();     
    curl_setopt($chCURLOPT_RETURNTRANSFER1); 
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_ANY);
    curl_setopt ($chCURLOPT_COOKIEJAR'cookie.txt');
    curl_setopt ($chCURLOPT_POSTFIELDS"current_form=loginForm&username=yourName&password=Unknown");
    ob_start();     
    curl_exec ($ch);
    ob_end_clean(); 
    curl_close ($ch);
    unset(
    $ch);
    $ch curl_init();
    curl_setopt($chCURLOPT_RETURNTRANSFER,1);
    curl_setopt($chCURLOPT_COOKIEFILE"cookie.txt");
    curl_setopt($chCURLOPT_URL,"http://www.yoursite.com/myform.php");
    $result curl_exec ($ch);

    curl_close ($ch);
    echo 
    $result;
    ?>

  6. #6
    SitePoint Addict
    Join Date
    Jan 2005
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!
    How do I get a the response body of the login form page? May be useful to verify if the log in is correct or not.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •