-1

I'm trying to use cURL with the proxy setting, which was working fine before I changed my password to use the @ sign.

This is how I define the proxy:

curl_setopt($curl, CURLOPT_PROXY, "http://test:test@test@10.20.5.15:90");

Is there any way to use a proxy pass with the @ sign (in my case the password is test@test) and get cURL to work?

user838437
  • 1,451
  • 7
  • 23
  • 31
  • 2
    Might wanna take a look: http://stackoverflow.com/questions/648292/escaping-curl-symbol-with-php – Logan Serman Jun 24 '12 at 10:53
  • possible duplicate of [How to use linux command line ftp with a @ sign in my username?](http://stackoverflow.com/questions/814322/how-to-use-linux-command-line-ftp-with-a-sign-in-my-username) - the same method can be used for the password parameter. – Lix Jun 24 '12 at 10:58
  • You should always attempt to find an existing post on the site before asking a new question. – Lix Jun 24 '12 at 10:59

2 Answers2

2

You can also use %40 instead of "@" :

curl_setopt($curl, CURLOPT_PROXY, "http://test:test%40test@10.20.5.15:90"); But it's better to use CURLOPT_USERPWD like @lix said ...

HamZa
  • 14,671
  • 11
  • 54
  • 75
1

You might want to try using the cURL set_opts methods to set your username and password.

CURLOPT_USERPWD
A username and password formatted as "[username]:[password]" to use for the connection.

An example would look like this -

curl_setopt($curl, CURLOPT_USERPWD, "test:test@test"); 
Lix
  • 47,311
  • 12
  • 103
  • 131
  • what if the password contains `:` ? – beppe9000 Jul 29 '20 at 01:53
  • @beppe9000 - you can try use the url encoded version of `:` which is `%3A`. I used this site to convert it https://www.urlencoder.org/. – Lix Jul 29 '20 at 11:04
  • Thats the same kinda solution from the other answer – Lix Jul 29 '20 at 11:05
  • 1
    well php has a builtin `urlencode` function, so I'd use that, like so: `curl_setopt($curl, CURLOPT_USERPWD, urlencode($user).':'.urlencode($password).'@'.$host.':'.$port);` – beppe9000 Jul 29 '20 at 14:03