html - Is it possible to reload a parent php file WITHOUT javascript?[WORKS !]

Is it possible to reload a parent php file WITHOUT javascript ?I dont wanna use Javascript because if the client has disabled Javascript .

So I have a object and there should be a button to change the background color of the main page

parent.php:

<!doctype html>
<html>
  <head>
    <title>This is the title of the webpage!</title>
    <?php 
      session_start();
      $_SESSION['backgroundcolor'] = '#fcba03';
    ?>
  </head>
  <body style="background-color:<?php echo $_SESSION['backgroundcolor'];?>">
    <object data="changebackground.php" width="500" height="200">
    </object>
  </body>
</html>

changebackground.php:

<form action="" method="post">
  <input type="submit" value="change bgcolor" name="submit">
</form>

<?php
$var = "#ff0000";

if (isset($_POST['submit'])) {
  $_SESSION['backgroundcolor'] = $var;
}
?>

Answer

Solution:

To answer your literal question, the only solution I can think is to use the target element in either a link or a form (_top should work but _parent is probably more accurate):

  • _self: the current browsing context. (Default)
  • _blank: usually a new tab, but users can configure browsers to open a new window instead.
  • _parent: the parent browsing context of the current one. If no parent, behaves as _self.
  • _top: the topmost browsing context (the "highest" context that??�s an ancestor of the current one). If no ancestors, behaves as _self.

How to fit this with your current logic is a different subject. The main issue is that these elements require a manual user intervention: user has to click to trigger the action since we don't want JavaScript to do it for him. Thus you need to merge the change colour form with the reload parent frame feature. The most obvious way is to perform the colour changing action at parent.php.

Answer

Solution:

You can do it with PHP:

header("Refresh:0");

It refreshes your current page, and if you need to redirect it to another page, use following:

header("Refresh:0; url=page2.php");

Answer

Solution:

Thanks to ??lvaro Gonz??lez , I now solved the problem this is my Current script

Parent.php

<!doctype html>
<?php session_start();?>
<html>
  <head>
    <title>Change Backgroundcolor with pure PHP</title>
<?php 
          
      if(empty($_SESSION['backgroundcolor'])){
        $_SESSION['backgroundcolor']='#fcba03';
      }else{
      }
    ?>
 </head>
  <body style="background-color:<?php echo $_SESSION['backgroundcolor']; ?>;" >
  <?php 
    

    echo $_SESSION['backgroundcolor'];
    echo '<object data="changebackground.php" width="500" height="200">';
    
  ?>
    
          
    </object>
  </body>
</html>

changebackground.php

<form action="" method="post" target="_parent">
<input type="submit" value="change bgcolor" name="submit">
</form>

<?php
  session_start();  
  $var= "#ff0000";
if (isset($_POST['submit']) ) {
    $_SESSION['backgroundcolor']=$var;
    header("Refresh:0; url=parent.php");
};

?>

Source