Hello,
I need to Schedule admin module function, so trying to login with curl, but without success.
I want to set up cron job to:
http://www.example.com/admin/index.php? ... nctionname
But can't, because need to login... Maybe someone have a solution how to do this?
I need to Schedule admin module function, so trying to login with curl, but without success.
I want to set up cron job to:
http://www.example.com/admin/index.php? ... nctionname
But can't, because need to login... Maybe someone have a solution how to do this?
not sure if this would be helpful but here's another thread where we discussed a cron job to auto update specials end date: http://forum.opencart.com/viewtopic.php?f=20&t=116126
all you really need to do is form your query and you should be able to do pretty much anything.
all you really need to do is form your query and you should be able to do pretty much anything.
Yes, but also need execute the function manually from admin and I need quite a few things already written in admin models files, so I do not want write function in admin and do the same similar job with queries directly to mysql...billynoah wrote:assuming it's a database related task, why not just write the cron script to execute the query directly to the mysql server?
I found only this solution: http://opencart.hostjars.com/blog/16 , but it is old and not safe enough
This can help
You can first login to admin and then invoke your actions
http://blog.andyhunt.info/2011/12/21/us ... a-website/
You can first login to admin and then invoke your actions
http://blog.andyhunt.info/2011/12/21/us ... a-website/
Donate here to show support if you think I have helped you today!
Opencart Documentation
I try this example, but also without success. I get blank page or echo just "1"... I think I need to add &token=xxx to URL, but how to get token value after login?nvedia wrote:This can help
You can first login to admin and then invoke your actions
http://blog.andyhunt.info/2011/12/21/us ... a-website/
You cannot use curl to get to your admin page. The admin page requires the session token and the user to be logined. The easiest way is to move it to your front end, and adding a secret key which only your system knows.
Another option is to use an automation script like php selenium webdriver to get to admin page and perform your actions
Donate here to show support if you think I have helped you today!
Opencart Documentation
You CAN use curl to get to OC admin area. You just have to pass $_SESSION over with the curl call. I.e.:MarketInSG wrote:You cannot use curl to get to your admin page. The admin page requires the session token and the user to be logined.
Code: Select all
session_start();
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
session_write_close();
//create cURL connection
$curl_connection = curl_init('http://yourdomainname.com/admin/index.php?route=common/login');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_COOKIE, $strCookie );
//create array of data to be posted
$post_data['username'] = 'yourusername';
$post_data['password'] = 'yourpassword';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
http://nz1.php.net/curl_setopt#87112
and
http://thehungrycoder.com/general/how-t ... kopen.html
Thanks for help. Finally it works! Only the one thing I need to know $token to access next page.
Do not know if it the best way, bet maybe would helpfull for others...
and then
Do not know if it the best way, bet maybe would helpfull for others...
Code: Select all
$url = curl_getinfo($curl_connection)['url'];
$token = strstr($url, 'token=');
Code: Select all
curl_setopt($curl_connection, CURLOPT_URL, 'http://www.yourdomain.com/admin/index.php?route=module/yourmodule/funkction&'.$token);
well, what's the use of a cron job if you need to know the token as it will always be changing.
Who is online
Users browsing this forum: barnettgs, Google [Bot] and 137 guests