Hi. I am fairly new to php, but I do have plenty of programming experience (HTML, js, c, c++).. anyway.
I am building a website, where users may log on us
ing their private username/ password, after which they need to be logged in and redirected to another website using a master login/password - hidden from them. In other words, I need to submit a form automatically, server side. curl seems like my solution, but the problem is after the external website authenticates, it tries to redirect the browser to another page.. but the domain name stays my private one. Ex.
you are at www.mysite.com/login.php
you log in, and are supposed be redirected to www.anothersite.com/someaddr,
but instead the browser gets www.mysite.com/someaddr - which obviously doesn't exist.
Basically, after curl executes, the results are passed on to the browser - but the url stays the same. I need to pass the proper url as well (update it to www.anothersite.com/whatever..)
My code:
$url = "http://www.anothersite.com/login.jsp;
$params = "user=123&password=456;
$user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);//url
curl_setopt($ch, CURLOPT_POST,1);//
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_exec($ch);
curl_close ($ch);
//echo $result;
I hope this is detailed enough, and someone may be able to help me soon.
I may be missing something very simple, since I'm new to php.
Cheers.🙂