# Session Stickiness

### Establishing a session

The `sessionid` proxy header maintains the same IP address for unlimited time duration, as long as the IP remains in the pool. If the IP is no longer available or was removed due to quality problems, a new IP is assigned. To reuse an IP, use the same `sessionid` header with a unique identifier of 4 to 12 digits, e.g., `sessionid-42831931` .&#x20;

For session duration adjustments in case it is needed, contact us at <support@goproxies.com>.

### Credentials list of examples for different sessions

Examples below contain a list of credentials that establish a new unique session.

`customer-USERNAME-sessionid-1293812:PASSWORD`\
`customer-USERNAME-sessionid-2837218:PASSWORD`\
`customer-USERNAME-sessionid-3832892:PASSWORD`\
`customer-USERNAME-sessionid-585896:PASSWORD`\
`customer-USERNAME-sessionid-789129:PASSWORD`<br>

### Understanding sessionid header

When using a session ID like `customer-USERNAME-sessionid-912937:PASSWORD`, the proxy assigns an IP address (e.g., 1.1.1.1), which is valid indefinitely. Requests with the same `sessionid` will consistently return the same IP. A rare IP change might occur only if the current IP is no longer available in our pool.

### Request example

{% tabs %}
{% tab title="cURL" %}

```bash
curl --proxytunnel --proxy "https://customer-USERNAME-sessionid-7182391:PASSWORD@proxy.goproxies.com:1080" https://ip.goproxies.com
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');
const { HttpsProxyAgent } = require('https-proxy-agent');

const username = 'customer-USERNAME-sessionid-7182391';
const password = 'PASSWORD';
const proxyAuth = encodeURIComponent(username) + ':' + encodeURIComponent(password);
const proxyUrl = `http://${proxyAuth}@proxy.goproxies.com:1080`;
const agent = new HttpsProxyAgent(proxyUrl);

(async () => {
  try {
    const res = await axios.get('https://ip.goproxies.com', { httpsAgent: agent, timeout: 10000 });
    console.log(res.status, res.data);
  } catch (err) {
    console.error('request error:', err.message);
  }
})();
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from urllib.parse import quote

username = "customer-USERNAME-sessionid-7182391"
password = "PASSWORD"
proxy = f"http://{quote(username)}:{quote(password)}@proxy.goproxies.com:1080"

proxies = {
    "http": proxy,
    "https": proxy,
}

resp = requests.get("https://ip.goproxies.com", proxies=proxies, timeout=10)
print(resp.status_code)
print(resp.text)
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
	"time"
)

func main() {
	proxyURL, _ := url.Parse("http://customer-USERNAME-sessionid-7182391:PASSWORD@proxy.goproxies.com:1080")
	transport := &http.Transport{
		Proxy: http.ProxyURL(proxyURL),
		TLSHandshakeTimeout: 10 * time.Second,
	}
	client := &http.Client{Transport: transport, Timeout: 15 * time.Second}

	resp, err := client.Get("https://ip.goproxies.com")
	if err != nil {
		fmt.Println("request error:", err)
		return
	}
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println("status:", resp.Status)
	fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Java" %}

```java
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;

public class ProxySessionExample {
  public static void main(String[] args) throws Exception {
    String proxyHost = "proxy.goproxies.com";
    int proxyPort = 1080;
    String user = "customer-USERNAME-sessionid-7182391";
    String pass = "PASSWORD";

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
        new UsernamePasswordCredentials(user, pass));

    HttpHost proxy = new HttpHost(proxyHost, proxyPort);
    RequestConfig config = RequestConfig.custom().setProxy(proxy).build();

    try (CloseableHttpClient httpclient = HttpClients.custom()
             .setDefaultCredentialsProvider(credsProvider)
             .build()) {

      HttpGet httpget = new HttpGet("https://ip.goproxies.com");
      httpget.setConfig(config);

      try (CloseableHttpResponse response = httpclient.execute(httpget)) {
        System.out.println(response.getStatusLine());
        System.out.println(new String(response.getEntity().getContent().readAllBytes()));
      }
    }
  }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'uri'

username = 'customer-USERNAME-sessionid-7182391'
password = 'PASSWORD'

uri = URI('https://ip.goproxies.com')
proxy_addr = 'proxy.goproxies.com'
proxy_port = 1080

Net::HTTP::Proxy(proxy_addr, proxy_port, username, password).start(uri.host, uri.port, use_ssl: true) do |http|
  req = Net::HTTP::Get.new(uri)
  res = http.request(req)
  puts res.code
  puts res.body
end
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$ch = curl_init('https://ip.goproxies.com');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, 'proxy.goproxies.com:1080');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'customer-USERNAME-sessionid-7182391:PASSWORD');
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);

$response = curl_exec($ch);
if ($response === false) {
    echo 'cURL error: ' . curl_error($ch) . PHP_EOL;
} else {
    echo 'Response: ' . $response . PHP_EOL;
}
curl_close($ch);
```

{% endtab %}
{% endtabs %}
