Jump to content

Need help with this


tartou2

Recommended Posts

Hello everybody

I was thinking of a page that once is run, it auto-login from a form and auto submit data to another form which need the user to be logged in.

I have created these 2 pages it works perfectly but i am having a problem when it comes to cronjob. Even if the auto-login page is run first, for some reason, the account doesn't continue to be logged in and the data are not submitted from the second page because the account is not logged-in.

 

Anyone know how to help to bypass this issue and to make the server to login using cronjob without my interference ?

 

Everyone help who know how to do this is appreciated

Link to comment
Share on other sites

ok but there is still a problem

the login form is not on my website but on another website so how can i fis this code now

 

$post_data = 'userid=test1&password=test2';
$content_length = strlen($post_data);

header('POST login.php HTTP/1.1');
header('Host: http://thewebsite.com');
header('Connection: close');
header('Content-type: application/x-www-form-urlencoded');
header('Content-length: ' . $content_length);
header('');
header($post_data);

 

I am getting a 500 internal server error. How can i fix this ?

Link to comment
Share on other sites

ok i am using this now

 

<?php
session_start();

$host = 'www.thewebsite.com';
$service_uri = '/login.php';
$vars ='userid=test1&password=test2';

$header = "Host: $host\r\n";
$header = "POST $service_uri  HTTP/1.1\r\n";
$header .= "User-Agent: PHP Script\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($vars)."\r\n";
$header .= "Connection: close\r\n\r\n";


$server = 'localhost';
$database = '*****';
$dbusername = '*****';
$dbpassword = '*****';
$connection = mysql_connect($server,$dbusername,$dbpassword);

if (!$connection) {
die('Could not connect to MySQL database, the server return the error: '.mysql_error());
}
$db = @mysql_select_db($database);

$check=mysql_query("SELECT * FROM  data WHERE id=1");
$row=mysql_fetch_array($check);
$add_id=$row['add_id'];

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
<body onLoad="document.formdata.submit();">
<script type="text/javascript">
j=<?php echo $add_id; ?>;
document.write("<form method=POST name=formdata action=http://thewebsite.com/members/editbanners.php>");
document.write("<input type=hidden name=name maxsize=30 value=somevalue><br>");
document.write("<input type=hidden name=bannerurl maxsize=70 value=someurl>");
document.write("<input type=hidden name=targeturl maxsize=70 value=someotherurl>");
document.write("<input type=hidden name=id value="+j+">");
document.write("<input type=hidden name=done value=YES>");
document.write("<input type=submit value=someothervalue>");
document.write("</form>");
</script>

<?php
mysql_query("UPDATE data SET add_id=add_id+1 WHERE id=1");
?>  	

  </body>
</html>

 

I know i can remove the javascript code but the code was edited lately and i still haven't remove the javascript code.

Anyway now i am not receiving anymore the error but when the form is submitted, it doesn't log to the account.

How can i fix this ?

Link to comment
Share on other sites

typically, when a user is "logged in", a session is started for that user, and the user can continue browsing with the session.

 

if the server you are posting to uses sessions to maintain logged in status, you will not be able to log a user in on the other site as simply as you seem to expect.

 

but maybe I am mis-understanding the purpose of this project?

Link to comment
Share on other sites

typically, when a user is "logged in", a session is started for that user, and the user can continue browsing with the session.

 

if the server you are posting to uses sessions to maintain logged in status, you will not be able to log a user in on the other site as simply as you seem to expect.

 

but maybe I am mis-understanding the purpose of this project?

 

yes the website use session.

So anyway i can make a cronjob to run this code and to handle the session or anyway i make the data to be submitted from the form ?

Link to comment
Share on other sites

you won't be able to submit form data to a remote server and have a user be able be logged in that way unless (and only maybe) if you use curl functions to submit the data and manage session cookies. but you won't likely be able to set a cookie on the user's browser to tell the remote server that the user is logged in with an active session.

Link to comment
Share on other sites

okay, i think i did misunderstand. so there will be no user/browser.

 

you want to run a script to:

1. log in to remote server

2. submit data to another form that requires the visitor to be logged in

 

You are just logging in and submitting data? if so, you could probably do that with curl. here is an example i found via google.com that might work for you:

 

http://www.knowledgesutra.com/forums/topic/38162-automatic-login-using-curl/

Link to comment
Share on other sites

ok so this is the new code but it is not working

<?php
session_start();
$server = 'localhost';
$database = '*****';
$dbusername = '*****';
$dbpassword = '******';
$connection = mysql_connect($server,$dbusername,$dbpassword);

if (!$connection) {
die('Could not connect to MySQL database, the server return the error: '.mysql_error());
}
$db = @mysql_select_db($database);

$check=mysql_query("SELECT * FROM  data WHERE id=1");
$row=mysql_fetch_array($check);
echo $add_id=$row['add_id'];

// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://www.thewebsite.com/login.php');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'userid=test1&password=test2');

// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);

// SET FILE TO DOWNLOAD
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://www.thewebsite.com/members/editbanners.php');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'name=somevalue&bannerurl=someurl&targeturl=someotherurl&id='.$add_id.'&done=YES');

// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
$content = curl_exec ($ch);

// CLOSE CURL
curl_close ($ch); 

?>

 

Anyone can help me to fix this code ?

Link to comment
Share on other sites

Are you currently executing the script directly or are you waiting for the cron job to do it?  If you execute directly you can test to see whether or not you are getting errors in your script.  I noticed you have spaced between the function names and the braces.  Echo your sql query.  Echo the variables you are interested in.  Echo the result from the curl execution function.

Link to comment
Share on other sites

Have you done any debugging?

 

You really shouldn't use the "@" when developing code. It suppresses error messages. You should be checking that all of your mysql calls work.

 

Ken

 

all mysql syntax are working fine. the problem is in the curl syntax

Link to comment
Share on other sites

Are you currently executing the script directly or are you waiting for the cron job to do it?  If you execute directly you can test to see whether or not you are getting errors in your script.  I noticed you have spaced between the function names and the braces.  Echo your sql query.  Echo the variables you are interested in.  Echo the result from the curl execution function.

 

i did echo the curl execution and the mysql query but nothing appeared.

the mysql query show 2442 but nothing from the curl appeared

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.