Muddy_Funster Posted November 26, 2012 Share Posted November 26, 2012 Hi guys, I'm having a go at making a curl link that auto logs into another remote site. I managed to get the login part sorted after about a day of searching by using the CURLOPT_FOLLOWLOCATION and CURLOPT_COOKIEJAR settings to handle the session and the redirect after login, but I can't get the remote sites css and jquery paths to resolve as the cURL page keeps trying to use the reffrerential paths to the scripts with my server here, where obviously they don't exist. I have tried setting the CURLOPT_REFERER and CURLOPT_AUTOREFERER values but it's not made any difference, and from what I can read they arn't anything to do with my problem. I havn't used cURL for anything productive before so I'm not really femiliar with it. What am I missing that will let me tell the page to load the css and jquery using the remote server domain rather than my local one? Quote Link to comment https://forums.phpfreaks.com/topic/271184-curl-target-site-path-problem/ Share on other sites More sharing options...
Christian F. Posted November 26, 2012 Share Posted November 26, 2012 Have you set the CUROPT_COOKIEFILE parameter as well? The JAR file is only used for reading, cookies, while FILE is used for writing. Set them both to the same file, and you should be set. Quote Link to comment https://forums.phpfreaks.com/topic/271184-curl-target-site-path-problem/#findComment-1395155 Share on other sites More sharing options...
Muddy_Funster Posted November 26, 2012 Author Share Posted November 26, 2012 yeah - this is what I have so far : $ch = curl_init(); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, '/temp/curlJar.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, '/temp/curlJar.txt'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$login); curl_setopt($ch, CURLOPT_URL, "http://targeturl.com/targetLoginPage/LogOn?ReturnUrl=%2f"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $page = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); $pageFull = str_replace('"/', '"http://targeturl.com/', $page); echo $pageFull; using the str_replace workaround most of the css is coming up properly, but the java and some images are still causing a problem, I'm getting java alerts up to the efect of "Target page not found [404] URL /Home/KeepAlive" These are using the target sites CSS for styling, so I'm thinking it's something to do with telling the curl page what it's webroot is supposed to be - as I just demonstarted on that other post, directory stettings aren't my strong suit Quote Link to comment https://forums.phpfreaks.com/topic/271184-curl-target-site-path-problem/#findComment-1395159 Share on other sites More sharing options...
Christian F. Posted November 26, 2012 Share Posted November 26, 2012 (edited) Ah, sorry. Managed to misread your question. Thought you were having problems getting logged in. Anyway, if that's Java Applets that's showing you those errors, then I don't think there's much you can do with them. However, if they're Javascript errors, then you might have to do some deep voodoo to make them work. Also, I'm not sure on this, but I assume that the external stylesheets still reference the HTML document's server/domain. Which would explain why you're having issues with some pictures. Afraid I can't really help you more, at least not without seeing some specific examples of the problems you're having. The problem is quite theoretical and quite clouded at the moment, so I'm not certain what actually happens. Though, there's one thing I'm wondering about: Why are you displaying a remote site as if it were hosted on your server? Edited November 26, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/271184-curl-target-site-path-problem/#findComment-1395178 Share on other sites More sharing options...
Muddy_Funster Posted November 26, 2012 Author Share Posted November 26, 2012 It's for a sort of unified login system. Our end users do not tend to be overly computer litterate. Our suppliers have created a portal that our users can use to log in and order stuff, each portal is different with spcific delivery details and the such. The idea was that, instead of each end user having to have a shortcut set uip on the computer, and have the login information passed to them for them to either forget repetedly or write down in some obvious format that I would just stick a link in the intranet site that would launch the remote site and log them into it without them ever needing to know or worry about the details. As everything is run internaly through an MPLs I have already automated the identification of end users on the intranet by local IP address, so they never need to "log in" so to speak. I would be just as happy (infact, probably even happier) having the link open the remote site in a new window/tab - as long as the login was still taken care of. It's a basic post form so there is probably a couple of ways to do it, but cURL is the only thing that I have touched on that can. I thought that I might be able to bundle the info into a header() call, but that only seems to allow for url encoded data, like get, not post. the CSS didn't display at all untill I put in the str_replace() to add the target url into the $pageFull paths, but I have to assume that the js is linking to an external file that's probably using the same relative addressing to load the images and perform this KeepAlive. If you know anything that will solve this I'm open to suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/271184-curl-target-site-path-problem/#findComment-1395212 Share on other sites More sharing options...
Muddy_Funster Posted November 26, 2012 Author Share Posted November 26, 2012 Solved it, I just put a header(Location: ...) after the curl_exec(), without echoing the return, and jumped right over to the remote site, still riding on the session cookie that curl returned from the login. Exectly the result I was looking to achieve, just wish I thought of it sooner (especialy as now it seems so damn obvious). Quote Link to comment https://forums.phpfreaks.com/topic/271184-curl-target-site-path-problem/#findComment-1395228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.