set_cookie_for_url

set_cookie_for_url($url,$name,$cookie,$expires="",$domain="",$path="",$httpOnly=false,$secure=false,$session=false,$sameSite="",$priority=""); - set (add) cookies for the specified site

The input function accepts parameters:

  • $url – site address
  • $name – the name of the cookie or "" if the next parameter is not many cookies
  • $cookie – a string with cookies or cookies
  • Since version 7.0.43 $expires , $domain , $path , $httpOnly , $secure to set additional parameters for cookies.
  • Since version 7.0.53 $sameSite and $priority have been added to set the corresponding cookie properties.

    After testing, the function returns the result of its work to the script :
  • true – completed successfully
  • false – failed to execute

    PHP example:

    <?php $xhe_host = "127.0.0.1:7013";
     
    //connect the object to control the emulator, if not already connected
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> browser->".basename(__FILE__)."</font> <hr>";
     
    //1
    echo "1.Let's go to Google:";
    echo $browser->navigate("http://www.google.com/", "")."<br> <br>";
     
    //2
    echo "2.Get the current google cookies:";
    echo $browser->get_cookie_for_url("http://www.google.com/", "")."<br> <br>";
     
    //3
    echo "3.Clear the current google cookies.";
    $browser->clear_cookies("google.com", true, true);
     
    //4
    echo "<br> <br> 4.Get the current google cookies - empty:";
    echo $browser->get_cookie_for_url("http://www.google.com/", "")."<br> <br>";
     
    //five
    echo "5.Let's set(add) cookies to Google:";
    $cookie = "__ utma = 123272373.426502259.12244752769.12244752769.12424752775.2: __ utmb = 173272373.4.10.1244752775; __utmz = 173272373.1244752783.2.3.utmccn =(organic) | utmcsmctr = google | utmccn =(organic) | utmcsmctr adogle | utmse372.__utmv = 173272373.ExistingPublisher; PREF = ID = 1ab1131528cb1f1a: TM = 1244752750: LM = 1244752750: S = z8a6mTRmDHVImKOg; TZ = -180; GMAIL_RTT = 62; SID = DQAAAG4AAACVKgLK1udE8zJUkHfj7lB1exGg0rTbtWPXOIWORMueVZoT77XyJNTUltfGPonIuKt7PTVUs5qF-UvkhHR5cXcsIynN04AL3f7YMObLoOP5wkyGK9n7zHlw89Px0s8foYkobyH8Z9wzAZ2-FpZ7s9I3 ";
    echo $browser->set_cookie_for_url("http://www.google.com/", "", $cookie)."<br> <br>";
     
    //6
    echo "6.Get the current Google cookies(2 times): <br> <br>";
    echo $browser->get_cookie_for_url("http://www.google.com/", "")."<br> <br>";
    echo $browser->get_cookie()."<br> <br>";
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7013"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> browser.xxxxxxxxx </font> <hr>")
     
    # 1
    echo("1.Let's go to google:")
    echo(browser.navigate("http://www.google.com/", ""), "<br> <br>")
     
    # 2
    echo("2.Get the current google cookie:")
    echo(browser.get_cookie_for_url("http://www.google.com/", ""), "<br> <br>")
     
    # 3
    echo("3.Clear current google cookies.")
    browser.clear_cookies("google.com", true, true)
     
    # 4
    echo("<br> <br> 4.Get the current google cookies - empty:")
    echo(browser.get_cookie_for_url("http://www.google.com/", ""), "<br> <br>")
     
    # five
    echo("5.Set(Add) cookies to Google:")
    cookie = "__ utma = 123272373.426502259.12244752769.12244752769.12424752775.2: __ utmb = 173272373.4.10.1244752775) __utmz = 173272373.1244752783.2.3.utmccn =(organic) | utmcscmctr = google | utmccn =(organic) | utmcscmctr = google | utm372.= 173272373.ExistingPublisher) PREF = ID = 1ab1131528cb1f1a: TM = 1244752750: LM = 1244752750: S = z8a6mTRmDHVImKOg) TZ = -180) GMAIL_RTT = 62) SID = DQAAAG4AAACVKgLK1udE8zJUkHfj7lB1exGg0rTbtWPXOIWORMueVZoT77XyJNTUltfGPonIuKt7PTVUs5qF-UvkhHR5cXcsIynN04AL3f7YMObLoOP5wkyGK9n7zHlw89Px0s8foYkobyH8Z9wzAZ2-FpZ7s9I3 "
    echo(browser.set_cookie_for_url("http://www.google.com/", "", cookie), "<br> <br>")
     
    # 6
    echo("6.Get the current google cookie:")
    echo(browser.get_cookie_for_url("http://www.google.com/", ""), "<br> <br>")
    echo(browser.get_cookie(), "<br> <br>")
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #region using
     
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
     
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
     
    #endregion
     
     class Program: XHEScript
     {
    static void Main(string [] args)
    {
    //init XHE
    server = "127.0.0.1:7010";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> browser.set_cookie_for_url </font> <hr>");
     
    //1 step
    echo("1.Let's go to Google:");
    echo(browser.navigate("http://www.google.com/") + "<br>");
     
    //step 2
    echo("2.Get the current google cookie:");
    echo(browser.get_cookie_for_url("http://www.google.com/", "") + "<br>");
     
    //step 3
    echo("3.Clear current google cookies.");
    echo(browser.clear_cookies("google.com", true, true) + "<br>");
     
    //step 4
    echo("4.Get the current google cookies - empty:");
    echo(browser.get_cookie_for_url("http://www.google.com/", "") + "<br>");
     
    //step 5
    echo("5.Let's set(Add) cookies to Google:");
    string cookie = "__ utma = 123272373.426502259.12244752769.12244752769.12424752775.2: __ utmb = 173272373.4.10.1244752775; __utmz = 173272373.1244752783.2.3.utmccn =(organic) | utmcsmctr adogle.com | utmccn =(organic) | utmcsmctr adogle | utmccm72.__utmv = 173272373.ExistingPublisher; PREF = ID = 1ab1131528cb1f1a: TM = 1244752750: LM = 1244752750: S = z8a6mTRmDHVImKOg; TZ = -180; GMAIL_RTT = 62; SID = DQAAAG4AAACVKgLK1udE8zJUkHfj7lB1exGg0rTbtWPXOIWORMueVZoT77XyJNTUltfGPonIuKt7PTVUs5qF-UvkhHR5cXcsIynN04AL3f7YMObLoOP5wkyGK9n7zHlw89Px0s8foYkobyH8Z9wzAZ2-FpZ7s9I3 ";
    echo(browser.set_cookie_for_url("http://www.google.com/", "", cookie) + "<br>");
     
    //step 6
    echo("6.Get the current google cookies:");
    echo(browser.get_cookie_for_url("http://www.google.com/", "") + "<br>");
     
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7010";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> browser.set_cookie_for_url </font> <hr>");
     
    //1 step
    echo("1.Let's go to Google:");
    echo(browser.navigate("http://www.google.com/", "") + "<br> <br>");
     
    //step 2
    echo("2.Get the current google cookie:");
    echo(browser.get_cookie_for_url("http://www.google.com/", "") + "<br> <br>");
     
    //step 3
    echo("3.Clear current google cookies.");
    echo(browser.clear_cookies("google.com", true, true) + " n  n");
     
    //step 4
    echo("4.Get the current google cookies - empty:");
    echo(browser.get_cookie_for_url("http://www.google.com/", "") + "<br> <br>");
     
    //step 5
    echo("5.Let's set(Add) cookies to Google:");
    cookie = "__ utma = 123272373.426502259.12244752769.12244752769.12424752775.2: __ utmb = 173272373.4.10.1244752775; __utmz = 173272373.1244752783.2.3.utmccn =(organic) | utmcscmutr = google | utmccn = 173272373.ExistingPublisher; PREF = ID = 1ab1131528cb1f1a: TM = 1244752750: LM = 1244752750: S = z8a6mTRmDHVImKOg; TZ = -180; GMAIL_RTT = 62; SID = DQAAAG4AAACVKgLK1udE8zJUkHfj7lB1exGg0rTbtWPXOIWORMueVZoT77XyJNTUltfGPonIuKt7PTVUs5qF-UvkhHR5cXcsIynN04AL3f7YMObLoOP5wkyGK9n7zHlw89Px0s8foYkobyH8Z9wzAZ2-FpZ7s9I3 ";
    echo(browser.set_cookie_for_url("http://www.google.com/", "", cookie) + "<br> <br>");
     
    //step 6
    echo("6.Get the current google cookies:");
    echo(browser.get_cookie_for_url("http://www.google.com/", "") + "<br> <br>");
    echo(browser.get_cookie() + "<br> <br>");
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();