Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP - Post login data and then get the source of the page that requires login.

Posted on 2012-03-17
12
Medium Priority
?
569 Views
Last Modified: 2012-03-17
Hi there.

There is a login form on the page index.php

				<form method="POST" action="login.php">
					<table border="0" cellpadding="4" cellspacing="1" class="w12">
						<tr>
							<td>Login:</td>
							<td>
								<input type="text" name="username" class="b12">
							</td>
						</tr>
						<tr>
							<td>Password:</td>
							<td>
								<input type="password" name="password" class="b12">
							</td>
						</tr>
						<tr>
							<td colspan="2" align="right">
								<input type="submit" value="Login">
							</td>
						</tr>
					</table>
				</form>

Open in new window


When the form on index.php is posted, it generates session id on the same page and then passes login data to login.php.

How do I programmatically post the login data via php, and then get the source code of the page called sourceineed.php ?

Thank you.
0
Comment
Question by:mropenmind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 17

Accepted Solution

by:
selvol earned 1500 total points
ID: 37733140
CURL


<?php
class cURL {
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
function cURL($cookies=TRUE,$cookie='cookies.txt',$compression='gzip',$proxy='') {
$this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$this->compression=$compression;
$this->proxy=$proxy;
$this->cookies=$cookies;
}
function post($url,$data) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process, CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($process, CURLOPT_POST, 1);
$return = curl_exec($process);
$return = str_replace('<body ', '<!-- ', $return);
$return = str_replace('bgcolor="#FAf7EF"  >', ' -->', $return);
$return = str_replace('</TBODY>', '<!-- ', $return);
echo $return;
curl_close($process);}
}
$cc = new cURL();
$cc->post('http://YOURSITE','username=jones&password=letein');
?>

-->


SElvol
0
 

Author Comment

by:mropenmind
ID: 37733159
it returns nothing.
0
 
LVL 17

Expert Comment

by:selvol
ID: 37733160
The above is inclusive of a few more parameters the you requested but may need..

You may need the point 'cookies.txt' to that file.

To get the source of the page you need you could wrap that page in a shell.


<?php
$file=file_get_contents("THE above page url");

DO SOME THING WITH $file..

Selvol
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 

Author Comment

by:mropenmind
ID: 37733164
I'm trying to login to: http://gm.heroesofnewerth.com using PHP.
0
 
LVL 17

Expert Comment

by:selvol
ID: 37733174
Oh snaps. Apologies


Remove these lines.


$return = str_replace('<body ', '<!-- ', $return);
$return = str_replace('bgcolor="#FAf7EF"  >', ' -->', $return);
$return = str_replace('</TBODY>', '<!-- ', $return);

As they were hiding the <html>

Elvol
0
 

Author Comment

by:mropenmind
ID: 37733179
removed the lines at response is still nothing
0
 

Author Comment

by:mropenmind
ID: 37733188
If you post anything to login.php without session id, it just doesn't let you to login.
0
 
LVL 17

Expert Comment

by:selvol
ID: 37733189
Any way I can login?  To test this page?

mail85224@gmail.com

Selvol
0
 

Author Comment

by:mropenmind
ID: 37733190
I've sent you an email
0
 
LVL 17

Expert Comment

by:selvol
ID: 37733195
no
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37733808
You know that even if you succeed, you will only get the HTML generated by the PHP page and not the PHP source.
0
 

Author Comment

by:mropenmind
ID: 37733918
I know.... I don't need a PHP source.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Six Sigma Control Plans
Suggested Courses

730 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