I need to assign a SESSION variable of php, with the value arguments [0] of a function of js. Can it be done?
"PHP"................"JS"
$_SESSION['id_ad'] = arguments[0];
I need to assign a SESSION variable of php, with the value arguments [0] of a function of js. Can it be done?
"PHP"................"JS"
$_SESSION['id_ad'] = arguments[0];
The truth is missing data but I will try to help you, for example you could send them using a javascript file to the php using a variable of type GET for example: In the html file or javascript:
<script>location.replace("http://www.yourdomain.com/procesar.php?var=usuario1")</script>
In the file process.php:
<?php
session_start();
$_SESSION['id_ad'] = $_GET['var'];
echo $_SESSION['id_ad'];
//output = usuario1
On the other hand, if you do not want your data to be visible when you send it, you could send it via POST via ajax In javascript:
$.ajax({
url: 'procesar.php',
method : 'post',
data: {'var' : arguments[0]},
success: function (){
alert("datos enviados");
}
});
In the file process.php:
<?php
session_start();
$_SESSION['id_ad'] = $_POST['var'];
echo $_SESSION['id_ad'];
//output = usuario1
All this taking into account that the value of arguments [0] is user1