# Session Control

Session control types include rotating session and sticky session.

## **Rotating session:**

When configured:

• Dynamic IP Allocation: Assigns a new residential IP for every request

• Ideal for: High-anonymity use cases (e.g., anti-association analysis)

Configuration Rules:

● No session ID parameters required

● Enable Rotating Mode in the **Endpoint Generator** for immediate effect

{% hint style="success" %}
[**Click here**](/doc/proxies/residential-proxies/location-settings/country-region-entry-node.md) for a list of supported for a list of rotating session-whitelist country region node entry
{% endhint %}

## **Sticky session:**

The session ID parameter allows you to keep the same IP address to run multiple requests. To reuse the same IP multiple times, use `sessid` parameter after `username` with randomly created alphanumeric string, for example, `sessid-abc123`.

The `sesstime` parameter goes together with `sessid`, and allows you to prolong the session above 10 minutes or set a particular time for it.for example,`sessid-abc123-sesstime-10`The maximum session duration is **90 minutes**. The system will automatically rotate your IP once the preset time expires or if the IP becomes invalid.

{% hint style="danger" %}
*The sesstime does **not** guarantee completion of all requests before session expiration. Even if requests are still in progress, the session will terminate upon reaching the set time limit.*
{% endhint %}

<figure><img src="/files/NSpdh2N2YDbzNa5VLPBV" alt=""><figcaption></figcaption></figure>

The standard session time is 10 minutes or up to 90s of inactivity (no requests). After that, a new IP address is assigned automatically.&#x20;

> For example, your initial query with `sessid-abcde12345` assigned proxy IP address `1.1.1.1.` As long as you keep sending new requests with the same session ID and that IP address is online and available, the system will route your queries through `1.1.1.1.` If you stop sending requests for 60 seconds or the IP address is no longer online, the system will assign a new proxy IP. Your next query with `sessid-abcde12345` will be routed through a different IP address e.g. `1.1.1.2`.

Example represents a list of credentials that establish different sessions.

```
user-USERNAME-sessid-a234234-sesstime-15:PASSWORD
user-USERNAME-sessid-a345345-sesstime-30:PASSWORD
user-USERNAME-sessid-a456456-sesstime-45:PASSWORD
user-USERNAME-sessid-a567567-sesstime-90:PASSWORD
```

**Code example**

&#x20;`sessid-a123123-sesstime-10.`In this example We are using a US IP with `sessid` string and `sesstime` (10 minutes) in the username with the first request . All following requests will keep the same USA IP with further querieswe are adding&#x20;

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

```sh
curl -x "https://td-customer-USERNAME-country-us-sessid-a123123-sesstime-10:PASSWORD@t.na.thordata.net:9999" "https://ipinfo.thordata.com"
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

class csharp_https
{
    static void Main(string[] args)
    {
        Task t = new Task(DownloadPageAsync);
        t.Start();
        Console.ReadLine();
    }

    static async void DownloadPageAsync()
    {
        string page = "https://ipinfo.thordata.com";

        var proxy = new WebProxy("https://t.na.thordata.net:9999")
        {
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(
                userName: "td-customer-USERNAME-country-us-sessid-a123123-sesstime-10",
                password: "PASSWORD")
        };

        var httpClientHandler = new HttpClientHandler()
        {
            Proxy = proxy,
            ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
        };

        var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);
        var response = await client.GetAsync(page);

        using (HttpContent content = response.Content)
        {
            string result = await content.ReadAsStringAsync();
            Console.WriteLine(result);
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}
```

{% endtab %}

{% tab title="GO" %}

```go
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
)

const (
	resourceUrl = "https://ipinfo.thordata.com"
	proxyHost   = "t.na.thordata.net:9999"
	username    = "td-customer-USERNAME-country-us-sessid-a123123-sesstime-10"
	password    = "PASSWORD"
)

func main() {
	proxyUrl := &url.URL{
		Scheme: "https",
		User:   url.UserPassword(username, password),
		Host:   proxyHost,
	}

	client := http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyURL(proxyUrl),
		},
	}

	resp, err := client.Get(resourceUrl)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	bodyString := string(body)
	fmt.Println(bodyString)
}
```

{% 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.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
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.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class JavaHttps {
    public static final String username = "td-customer-USERNAME-country-us-sessid-a123123-sesstime-10";
    public static final String password = "PASSWORD";
    public static final int port = 9999;
    public static final String proxyHost = "2n96wp6t.na.thordata.net";
    public CloseableHttpClient client;

    public JavaHttps() {
        HttpHost proxy = new HttpHost(proxyHost, port, "https");
        CredentialsProvider cred_provider = new BasicCredentialsProvider();
        cred_provider.setCredentials(new AuthScope(proxy),
                new UsernamePasswordCredentials(username, password));
        client = HttpClients.custom()
                .setConnectionManager(new BasicHttpClientConnectionManager())
                .setProxy(proxy)
                .setDefaultCredentialsProvider(cred_provider)
                .build();
    }

    public String request(String url) throws IOException {
        HttpGet request = new HttpGet(url);
        CloseableHttpResponse response = client.execute(request);
        try {
            return EntityUtils.toString(response.getEntity());
        } finally { response.close(); }
    }

    public void close() throws IOException { client.close(); }

    public static void main(String[] args) throws IOException {
        JavaHttps client = new JavaHttps();
        try {
            System.out.println(client.request("https://ipinfo.thordata.com"));
        } finally { client.close(); }
    }
}

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
  $url = 'https://ipinfo.thordata.com';
  $proxy = 't.na.thordata.net';
  $port = 9999;
  $user = 'td-customer-USERNAME-country-us-sessid-a123123-sesstime-10';
  $psw = 'PASSWORD';

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_PROXY, "$proxy:$port");
  curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$user:$psw");
  $result = curl_exec($ch);
  curl_close($ch);

  if ($result)
  {
      echo $result . PHP_EOL;
  }
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

username = "td-customer-USERNAME-country-us-sessid-a123123-sesstime-10"
password = "PASSWORD"
proxy_server = "t.na.thordata.net:9999"

proxies = {"https": f"https://{username}:{password}@{proxy_server}"}

response = requests.get("https://ipinfo.thordata.com", proxies=proxies)
print(response.text)
```

{% endtab %}

{% tab title="Node.js" %}

```
const rp = require('request-promise');

const username = "td-customer-USERNAME-country-us-sessid-a123123-sesstime-10";
const password = "PASSWORD";
const proxyServer = "t.na.thordata.net:9999";

rp({
    url: 'https://ipinfo.thordata.com',
    proxy: `https://${username}:${password}@${proxyServer}`,
})
.then(function(data) {
    console.log(data);
})
.catch(function(err) {
    console.error(err);
});
```

{% endtab %}

{% tab title="Untitled" %}

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

proxy_host = 't.na.thordata.net'
proxy_port = 9999
proxy_user = 'td-customer-USERNAME-country-us-sessid-a123123-sesstime-10'
proxy_pass = 'PASSWORD'

uri = URI.parse('https://ipinfo.thordata.com')

proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass)

req = Net::HTTP::Get.new(uri)

result = proxy.start(uri.host, uri.port, use_ssl: true, ssl_version: :TLSv1_2) do |http|
  http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
[**Click here**](/doc/proxies/residential-proxies/location-settings/country-region-entry-node.md) for a list of supported for a list of sticky session-whitelist country region node entry
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.thordata.com/doc/proxies/residential-proxies/session-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
