Get File Contents/Source using POST first

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • distraction
    New Member
    • Feb 2008
    • 5

    Get File Contents/Source using POST first

    I am trying to post a login first then get the source of another page on that same server I posted to in order to get a specific value by element. It is required that you login before you can get the value. Anyways, is it possible before I run file_get_conten ts on my PHP page to POST to a login script/web service so I can get a specific value instead of the login page itself? Some sample code would be much appreciated.
  • adamalton
    New Member
    • Feb 2007
    • 93

    #2
    Can you clarify this a bit? You want someone to login and THEN let them have access to another page or a value within it, like from a database or something?

    Can you not just create a login page and then redirect them to the page that contains the info?

    Soemthing like:
    login.html
    [HTML]<html><body>
    <form action="validat e_login.php" method="post">
    <input type="text" name="username" >
    <input type="password" name="password" >
    <input type="submit" value="Login">
    </form>[/HTML]
    validate_login. php
    [PHP]<?php
    if($_POST['username']=="valid username" && $_POST['password']=="secret word"){

    session_start() ;
    $_SESSION['logged_in']=true;
    header("Locatio n: page_with_stuff _on_it.php");
    }
    else{//if their username/password were not valid
    header("Locatio n: login.html");//send them back to the login page
    }
    ?>[/PHP]
    page_with_stuff _on_it.php
    [PHP]<?php
    session_start() ;
    if($_SESSION['logged_in']){//if they ARE logged in
    print "secret stuff goes here";
    }
    else{
    print "You are not allowed to see the secret stuff";
    }
    ?>[/PHP]

    Comment

    • distraction
      New Member
      • Feb 2008
      • 5

      #3
      Yes, I will try to clarify. The action method to the form is not on my domain, it is on another domain. I would like to pass the login information via action method and once they are logged into that domain--I need to redirect to another page on their domain to get a different form element's value returned to me. The only way to get a cross-domain's element back to me is through a server side proxy which returns the element back to me nicely except I need it to login because if I do not, then the other page on that domain will not give the correct value since the user did not login on that through that same proxy.

      I was thinking I could use file_get_conten ts($_POST['url']) to get the value I need via iframe except if I do a form to login to that domain before getting contents, it will not give me the correct value because the same method needs to login first before getting contents.

      I have tried AJAX with some CGI/Perl and maybe that is the most reasonable approach, however, I was thinking there was some clever way to implement this in PHP. Someone once suggested cURL but I did a little research on this and wasn't really too sure how to get it done.

      Comment

      Working...