By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Get File Contents/Source using POST first

P: 5
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_contents 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.
Feb 9 '08 #1
Share this Question
Share on Google+
2 Replies


P: 93
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="validate_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("Location: page_with_stuff_on_it.php");
}
else{//if their username/password were not valid
header("Location: 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]
Feb 10 '08 #2

P: 5
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_contents($_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.
Feb 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.