php


PHP cURL with post data login not working where wget with shell_exec is


I'm trying to access remote files on a website that requires me to log in to it. The current way I'm doing this is with a wget ran from shell_exec. This 'works' but is definitly not the way I want to do it in. I would prefer to do it using cURL, but for some reason this will not work for me.
What happens instead of getting the page I requested is I'm redirected to the login page, which does not happen with the wget method, which should be making the exact same request...
What am I doing wrong?
First of all this is the current (not nice but) working method of accessing the page:
shell_exec("wget --post-data='serviceLoginUser=something&serviceLoginPass=something&qq=login' -p https://internal.website.com/somepage.php?get=request -O return.json");
This is my download function which does not work but I want to replace the old way with: (updated after suggestion from Abkarino)
public function download($url, $postData = NULL){
//Set cURL options
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_HEADER, 0);
//To act like a normal browser (needed for intranet)
curl_setopt($this->ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
curl_setopt($this->ch, CURLOPT_AUTOREFERER, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
//TODO: remove
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
//If POST data was supplied:
if ($postData != NULL){
curl_setopt($this->ch,CURLOPT_POSTFIELDS, $postData);
}
//execute post
return curl_exec($this->ch);
}
Where the following code will form the request: (currenly this code is only to test if the cURL actually returns the correct data)
include 'Downloader.php';
$dl = new Downloader;
$postData = array(
'serviceLoginUser' => 'something',
'serviceLoginPass' => 'something',
'qq' => 'login'
);
echo $dl->download("https://internal.website.com/somepage.php?get=request", $postData);

Related Links

MySQL replace comma separated values in column with another table find old value to replace with new
Rewrite one Domain to Another without changing Address bar
is it valid to use php inside jquery?
symfony 2 - object created twice
How to write global functions in Yii2 and access them in any view (not the custom way)
PHP Contact Form for Bootstrap [duplicate]
Updating mysql DB with form
Multidimensional array inner items not printing
How can i use the Middleware “basic.auth” with a special group?
Odoo Webservices in PHP using XMLRPC
Wordpress Ajax Not Outputting Buffers When In Nopriv Ajax
PHP Strict Standards: Only variables should be passed by reference [duplicate]
php multidimensional array group number of occurrences by type and date
Laravel 5 global date accessor
load and parse HTML string
get all data from a variable

Categories

HOME
firebase
android-studio
eclipse-plugin
nsview
filesize
slider
jersey-2.0
azure-mobile-services
fasm
erd
tiff
pywinauto
google-tasks-api
office-ui-fabric
adobe-illustrator
ruby-daemons
tortoisehg
iwebbrowser2
sendmessage
ninject
ibm-connections
john-the-ripper
apptentive
char-pointer
buildforge
busboy
cartopy
ng-repeat
recovery
grails-spring-security
flipkart
hypothesis-test
minikube
virtual-memory
permission-denied
oracle-bmcs
dredd
viewmodel
scala-breeze
password-hash
ilrepack
punctuation
lvalue
.when
openquery
dmarc
android-4.2-jelly-bean
simian
persistent-object-store
deeplink
smart-tv
ibm-was
largenumber
netdatacontractserializer
unhandled
cache-manifest
actionpack
physicsjs
clarion
rfc5545
lifetime
windows-messages
senchatouch-2.4
rails-api
thruway
refit
cidr
radius-protocol
jack
cloo
codahale-metrics
ember-table
semantic-merge
chronometer
websphere-6.1
kolite
qtextbrowser
fork-join
upshot
digiflow
webresponse
jdownloader
android-input-method
iphone-sdk-3.1.3
version-control-migration

Resources

Encrypt Message