Title: Requests_Session::__set
Published: August 16, 2016
Last modified: November 2, 2022

---

# Requests_Session::__set( string $key, mixed $value )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#source)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#wp--skip-link--target)

Set a property’s value

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#parameters)󠁿

 `$key`stringrequired

Property key

`$value`mixedrequired

Property value

## 󠀁[Source](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#source)󠁿

[View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/session.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/Requests/Session.php#L99)

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/classes/requests_session/__set/?output_format=md#comment-content-5635)
 2.   [Hakik Zaman](https://profiles.wordpress.org/hakik/)  [  4 years ago  ](https://developer.wordpress.org/reference/classes/requests_session/__set/#comment-5635)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Frequests_session%2F__set%2F%23comment-5635)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Frequests_session%2F__set%2F%23comment-5635)
 4. If want to add a **session** for other pages but need to destroy that **session**
    on the front page. Then the code will be like this-
 5.     ```php
        function my_session(){
    
        	// Instance of Requests_Session class
        	$request_session = new Requests_Session();
    
        	// Destroying the session if it is front page of the site and the session exists
        	if( is_front_page() && $request_session->__isset( 'test' ) ){
        		$request_session->__unset( 'test' );
        	}
    
        	// Adding the session if it is not front page of the site and the session not exists
        	if( !is_front_page() && !$request_session->__isset( 'test' ) ){
        		$request_session->__set( 'test', 'my test' );
        		echo $request_session->__get( 'test' );
        	}
    
        }
        add_action('template_redirect', 'my_session');
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Frequests_session%2F__set%2F%3Freplytocom%3D5635%23feedback-editor-5635)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Frequests_session%2F__set%2F)
before being able to contribute a note or feedback.