# PHP and Javascript Variables

**URL:** <https://forum.kirupa.com/t/php-and-javascript-variables/62510>\
**Category:** programming\
**Created:** [August 28, 2004, 5:01pm UTC](https://forum.kirupa.com/t/php-and-javascript-variables/62510 "2004-08-28T17:01:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ViperBlaze](https://avatars.discourse-cdn.com/v4/letter/v/7feea3/32.png) [@ViperBlaze](https://forum.kirupa.com/u/ViperBlaze)\
**Post date:** [August 28, 2004, 5:01pm UTC](https://forum.kirupa.com/t/php-and-javascript-variables/62510/1 "2004-08-28T17:01:09Z")

</div>

Is there any way to transfer variables from javascript to php?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2004, 2:18pm UTC](https://forum.kirupa.com/t/php-and-javascript-variables/62510/2 "2004-09-01T14:18:47Z")

</div>

I don’t know PHP but it is serverside and JavaScript is a client side. So its not possible to have them communicate because the php code is executed before it is sent to the client.

The only way to get the javascript variable to php is to send it in the url.

yourpage.php?yourJSvar=1

Like I said though, I don’t know php so there may be some crazy way but I don’t think there is.

Hope that helps, khamstra

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2004, 12:57pm UTC](https://forum.kirupa.com/t/php-and-javascript-variables/62510/3 "2004-09-02T12:57:43Z")

</div>

Well in that case, does anyone know a script in php that gets the site the viewer came from. I know how to do it in Javascript,

```php
document.referrer()

```

But I’m not sure how to do it in php.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2004, 3:33pm UTC](https://forum.kirupa.com/t/php-and-javascript-variables/62510/4 "2004-09-02T15:33:45Z")

</div>

I’m can’t remember but it’s either $\_SERVER[‘HTTP\_FROM’]; or $\_SERVER[‘FORWARDED’];

But you can transfer variables from php to javascript acutally… as simple as  
\<?php echo ‘\<script type=“text/javascript”\> var1 = foo; \</script\>’; ?\>  
like writing js with php 😉
