How to run a piece of code from js to php?

There is a handler in jQuery that when you click on the "hide" minimizes certain elements:
$(document).ready(function() {
...
$('.hide').click(function() { ... })
...
});

I need to make it so that when you first enter the website the user this piece was normally deployed, and when re-entry is minimized, I try to make it through the session:

<?php 
session_start();

if(isset($_SESSION['name'])){
 here it is necessary to perform an action button "hide"
}
 $_SESSION['name'] = "test";
 ?>

Tell me how it can be implemented? In the handler for the button quite a lot, maybe it can be wrapped somehow into a function and call it from php?
July 8th 19 at 16:34
3 answers
July 8th 19 at 16:36
Solution
if(isset($_SESSION['perviy_vhod'])){
 echo '<script>
$(function(){
$('.hide').trigger('click');
 }); 
</script>';
 $_SESSION['perviy_vhod'] = 'perviy_vhod_vipolnen';
}
I need to check thanks - Sasha.Gorczany commented on July 8th 19 at 16:39
Error: Uncaught ReferenceError: $ is not defined – - Sasha.Gorczany commented on July 8th 19 at 16:42
Not to be confused with the quotes better. And we need to make sure that jQuery is connected
if(isset($_SESSION['perviy_vhod'])){
?>
$(function(){
$('.hide').trigger('click');
});

$_SESSION['perviy_vhod'] = 'perviy_vhod_vipolnen';
} - dalton_Mora commented on July 8th 19 at 16:45
: quotation marks inside the script to replace the double - Mathias_Ullrich commented on July 8th 19 at 16:48
July 8th 19 at 16:38
Solution
"Fulfill the press" or "to uncover the right piece"?
You can specify the variable the status of the container in JS (JS):
var expanded=<?=if($_SESSION['nextView'])?"false":"true"?>;

And below (AFTER CHECKING!)- set variable (in PHP):
if(!isset($_SESSION['nextView']))$_SESSION['nextView']=true;

In the end, for the first time - the variable$_SESSION['nextView'] will not be in JS variable expanded=true
So when you call $_SESSION['nextView']=true and expanded=false.
the answer has already been found - thanks , but your solution helped , is wrong - Sasha.Gorczany commented on July 8th 19 at 16:41
OK, enlighten me then, how is it done. - Sasha.Gorczany commented on July 8th 19 at 16:44
my answer view - dalton_Mora commented on July 8th 19 at 16:47
: this is the same thing that I wrote. - Mathias_Ullrich commented on July 8th 19 at 16:50
: I outlined the solution in your proposal - Sasha.Gorczany commented on July 8th 19 at 16:53
And, You just wrote that "it is wrong" - I was surprised. Thank you! - Kyleigh_Hills commented on July 8th 19 at 16:56
: I'm sorry for my " Albanian " - Sasha.Gorczany commented on July 8th 19 at 16:59
July 8th 19 at 16:40
Solution
the solution has been found independently :

<?php 
session_start();

if(isset($_SESSION['first_in'])){
?>
 <script src="libs/jquery/jquery-1.11.1.min.js"></script>
 <script src="common.js"></script>
 <script type="text/javascript"> 
 $(document).ready(function() {
$('.hide').trigger('click');
 }); 
</script>
<?php
}
$_SESSION['first_in'] = "first_in_ok";
?>
This is the worst solution of those proposed. From the first entrance or not you connect or not to connect the whole library. Is it anywhere on the website you jquery is no longer used?
The most beautiful, clear and simple solution to xmoonlight. But if the js in a separate file and inconvenient to assign a js variable value from php, you can add a class in html, and depending on the class to determine whether this is the first entry. - Sasha.Gorczany commented on July 8th 19 at 16:43

Find more questions by tags PHPjQuery