Hello again, my DynamoGeek friends!
I'm going to forego most of the time consuming fancy words today and just dump some (hopefully) useful information.
I had need to access a website via cURL through a VPN using PHP. Though my specific current VPN of choice is NordVPN, theoretically this information could be applied to any SOCKS based VPN service that requires authentication.
To help out those in the back of the room, and the search engines, I'll summarize what I did more concisely. I wrote some spiffy PHP code that proxies requests for webpages through NordVPN using cURL.
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_PROXY, 'us1111.nordvpn.com'); // Any SOCKS capable proxy URL
- curl_setopt($ch,CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); // Sets the proxy type for the connection to SOCKS
- curl_setopt($ch,CURLOPT_PROXYPORT,'1080'); // The port that NordVPN uses for all SOCKS connections
- curl_setopt($ch, CURLOPT_HEADER, FALSE); // Prevents the header from being included in the results
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Allows the connection to be redirected
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Causes the response to be returned as a string
- curl_setopt($ch, CURLOPT_PROXYUSERPWD, "Username:Password"); // Don't put your creds directly in the code
- curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); // Sets the authentication type for proxy connections
- curl_setopt($ch, CURLOPT_URL, $url); // I refuse to explain this option
- $results = curl_exec($ch); // The results of the request will end up in $results
I hope you've found this quick bit of information useful, and I'll see you next time.