Question: I am trying to run a Javascript file via conditions based on the request, (A.K.A. the previous URL) that the current page was accessed from. For example, if the user was redirected **to the login page**, logged in, and then **returned to the previous page**, that would trigger the JavaScript (whereas simply visiting the page would not).

Does **WordPress** or **PHP** have a way to check the request source?

Update:
-------

*WOOOOAAAH, WE'RE HALFWAY THEEERE!* 

Based on **user1091949**'s suggestion, I have gone ahead and added code to run my JavaScript file based on the presence of a **cookie**:

```
if ( !isset( $_COOKIE['mmmcookies'] ) ) {
    setcookie( 'mmmcookies', 1, 5 );
}

function media_kit_script() {
    $page_id = get_queried_object_id();
    if ( isset( $_COOKIE['mmmcookies'] ) ) {
            if ($page_id === 1947) {
                wp_enqueue_script( 'media-kit-init' );
            }
    }
}

add_action( 'wp_enqueue_scripts', 'media_kit_script' );

```

The script is registered in a previous function, and everything works! Now, here's my next question: I need to implement `setcookie()` based on the fact that the user has come from logging in, i.e.:

```
if ( user_came_from_login() ) {
    if ( !isset( $_COOKIE['mmmcookies'] ) ) {
    setcookie( 'mmmcookies', 1, 5 );
    }

```

And so on. **How would I do this?**

Answer: 
You could use a cookie. The start page:

```
if (!isset($_COOKIE['iwashere'])) {
    setcookie('iwashere', 1, time()+315360000);
}

```

The page where Javascript is needed if the user came from the page above:

```
if (isset($_COOKIE['iwashere'])) {
    echo '<script src="someJavascript.js"></script>';
}

```

Of course, you may need to change the expire time for the cookie.
That would be the referer (and it's not very reliable):

```
$_SERVER['HTTP_REFERER'];

```

Wordpress has it's [own version](http://codex.wordpress.org/Function_Reference/wp_get_referer):

```
wp_get_referer()

```

that accesses `$_REQUEST['_wp_http_referer'])` internally