lolitseasy
Member
Is it possible to use php curl to programmatically login into a website in background and traverse links and simulate button clicks?
Hello Everyone,
I want some information PHP GET and Post method...
please replay my thread...
[COLOR=#A71D5D]var[/COLOR] system [COLOR=#A71D5D]=[/COLOR] [COLOR=#0086B3]require[/COLOR]([COLOR=#DF5000]'system'[/COLOR]);
[COLOR=#969896]// Exit in case of wrong parameter count.[/COLOR]
[COLOR=#A71D5D]if[/COLOR] (system.args.[COLOR=#0086B3]length[/COLOR] [COLOR=#A71D5D]!==[/COLOR] [COLOR=#0086B3]3[/COLOR]) {
[COLOR=#795DA3]console[/COLOR][COLOR=#0086B3].log[/COLOR]([COLOR=#DF5000]'Usage: scriptname targetUrl referrer'[/COLOR]);
[COLOR=#795DA3]console[/COLOR][COLOR=#0086B3].log[/COLOR]([COLOR=#DF5000]'example: $> phantomjs fake-referrer.phantom.js http://example.com http://referrer.example.com'[/COLOR]);
phantom.exit();
}
[COLOR=#969896]// Set the important pieces[/COLOR]
[COLOR=#A71D5D]var[/COLOR] targetUrl [COLOR=#A71D5D]=[/COLOR] system.args[[COLOR=#0086B3]1[/COLOR]];
[COLOR=#A71D5D]var[/COLOR] referrer [COLOR=#A71D5D]=[/COLOR] system.args[[COLOR=#0086B3]2[/COLOR]];
[COLOR=#795DA3]console[/COLOR][COLOR=#0086B3].log[/COLOR]([COLOR=#DF5000]'Going to open '[/COLOR][COLOR=#A71D5D]+[/COLOR]targetUrl[COLOR=#A71D5D]+[/COLOR][COLOR=#DF5000]' with the referrer '[/COLOR][COLOR=#A71D5D]+[/COLOR]referrer);
[COLOR=#A71D5D]var[/COLOR] page [COLOR=#A71D5D]=[/COLOR] [COLOR=#0086B3]require[/COLOR]([COLOR=#DF5000]'webpage'[/COLOR]).create();
[COLOR=#969896]// set our custom referer [sic][/COLOR]
page.customHeaders [COLOR=#A71D5D]=[/COLOR] {
[COLOR=#DF5000]"Referer"[/COLOR] [COLOR=#A71D5D]:[/COLOR] referrer
};
[COLOR=#0086B3]page[/COLOR].[COLOR=#795DA3]onLoadFinished[/COLOR] [COLOR=#A71D5D]=[/COLOR] [COLOR=#A71D5D]function[/COLOR](status){
[COLOR=#969896]// get the currentUrl[/COLOR]
[COLOR=#A71D5D]var[/COLOR] currentUrl [COLOR=#A71D5D]=[/COLOR] page.evaluate([COLOR=#A71D5D]function[/COLOR]() {
[COLOR=#A71D5D]return[/COLOR] [COLOR=#0086B3]document[/COLOR].[COLOR=#0086B3]location[/COLOR].[COLOR=#0086B3]href[/COLOR];
});
[COLOR=#969896]// get the referrer[/COLOR]
[COLOR=#A71D5D]var[/COLOR] currentReferrer [COLOR=#A71D5D]=[/COLOR] page.evaluate([COLOR=#A71D5D]function[/COLOR]() {
[COLOR=#A71D5D]return[/COLOR] [COLOR=#0086B3]document[/COLOR].[COLOR=#0086B3]referrer[/COLOR];
});
[COLOR=#795DA3]console[/COLOR][COLOR=#0086B3].log[/COLOR]([COLOR=#DF5000]'Loading '[/COLOR] [COLOR=#A71D5D]+[/COLOR] currentUrl [COLOR=#A71D5D]+[/COLOR] [COLOR=#DF5000]' finished with status: '[/COLOR] [COLOR=#A71D5D]+[/COLOR] status[COLOR=#A71D5D]+[/COLOR][COLOR=#DF5000]'. document.referrer is: '[/COLOR][COLOR=#A71D5D]+[/COLOR]currentReferrer);
[COLOR=#969896]// Only once do[/COLOR]
[COLOR=#A71D5D]if[/COLOR] ( page.firstLoad ) {
page.firstLoad [COLOR=#A71D5D]=[/COLOR] [COLOR=#0086B3]false[/COLOR];
[COLOR=#795DA3]console[/COLOR][COLOR=#0086B3].log[/COLOR]([COLOR=#DF5000]'Injecting the Link.'[/COLOR]);
[COLOR=#969896]// Inject and Click a Link to our target[/COLOR]
page.evaluate([COLOR=#A71D5D]function[/COLOR] (href) {
[COLOR=#969896]// Create and append the link[/COLOR]
[COLOR=#A71D5D]var[/COLOR] link [COLOR=#A71D5D]=[/COLOR] [COLOR=#0086B3]document[/COLOR].[COLOR=#0086B3]createElement[/COLOR]([COLOR=#DF5000]'a'[/COLOR]);
link.[COLOR=#0086B3]setAttribute[/COLOR]([COLOR=#DF5000]'href'[/COLOR], href);
[COLOR=#0086B3]document[/COLOR].[COLOR=#0086B3]body[/COLOR].[COLOR=#0086B3]appendChild[/COLOR](link);
[COLOR=#969896]// Dispatch Click Event on the link[/COLOR]
[COLOR=#A71D5D]var[/COLOR] evt [COLOR=#A71D5D]=[/COLOR] [COLOR=#0086B3]document[/COLOR].createEvent([COLOR=#DF5000]'MouseEvents'[/COLOR]);
evt.initMouseEvent([COLOR=#DF5000]'click'[/COLOR], [COLOR=#0086B3]true[/COLOR], [COLOR=#0086B3]true[/COLOR], [COLOR=#0086B3]window[/COLOR], [COLOR=#0086B3]1[/COLOR], [COLOR=#0086B3]1[/COLOR], [COLOR=#0086B3]1[/COLOR], [COLOR=#0086B3]1[/COLOR], [COLOR=#0086B3]1[/COLOR], [COLOR=#0086B3]false[/COLOR], [COLOR=#0086B3]false[/COLOR], [COLOR=#0086B3]false[/COLOR], [COLOR=#0086B3]false[/COLOR], [COLOR=#0086B3]0[/COLOR], link);
link.dispatchEvent(evt);
}, targetUrl);
} [COLOR=#A71D5D]else[/COLOR] {
[COLOR=#795DA3]console[/COLOR][COLOR=#0086B3].log[/COLOR]([COLOR=#DF5000]'Exiting'[/COLOR]);
phantom.exit();
};
};
page.firstLoad [COLOR=#A71D5D]=[/COLOR] [COLOR=#0086B3]true[/COLOR];
page.[COLOR=#0086B3]open[/COLOR](referrer);