Variable value in arguments [0] to session variable

2

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];
    
asked by GERMAN SOSA 03.10.2018 в 21:18
source

1 answer

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

    
answered by 03.10.2018 в 21:56