I am trying to make a login php post but its not posting correctly... i need the following sent to the Curl but its just not sending
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'j_username='.$username.'&j_password='.$password.'&tk_trp ='.$tk_trp);
Is what i am currently trying to use and its just not taking is there something anyone notices that i am doing wrong? Any advice would be great thanks!
I have been stuck on this a good while now and its just not coming together for me so thought i would reach out :)
<?php
$token = GetStringBetween(getURL("tokenlocatonurl"),"start'", "'");
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
$username = 'myuser';
$password = 'mypass';
$tk_trp = '$token';
$loginUrl = 'lognurlhere';
function getURL($u){
$u = file_get_contents("http://{$u}");
return $u != false ? $u : "";
}
function GetStringBetween($string, $start, $finish){
$string = " ".$string;
$position = strpos($string, $start);
if ($position == 0) return "";
$position += strlen($start);
$length = strpos($string, $finish, $position) - $position;
return substr($string, $position, $length);
}
//init curl
$ch = curl_init();
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters curl_setopt($ch, CURLOPT_POSTFIELDS, 'j_username='.$username'&j_password='.$password'&tk_trp='.$tk_trp');
//Handle cookies for the login
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 the request (the login)
$store = curl_exec($ch);
//the login is now done and you can continue to get the
//protected content.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'url to grab content from');
//execute the request
$content = curl_exec($ch);
?>