Hello,

I was wondering what the best way would be to create a new page when a button is clicked. On this page would be the information from the form that was filled out. Then when the page is created, it has a randomly generated name. Then the link is displayed on the page with the button so you can copy and paste it etc.

It's not hard to explain, I am just really stupid at explaining stuff.

TIA

    It really depends on your end goal and how the data is generated, do you want to create a fresh .php file? Or display information generated from a database?

      I want to create a fresh php file. Which displays for example:

      Price
      Description of item
      Who made the item

      And then I plan on making those pages expire within 24 hours (deleting the pages)

      So it's essentially taking the profile name of the user logged in, the values from the forms they filled out, and then when they clicked the submit button, it generates a new randomly named php page with that info displayed if you know what I mean.

        <?php
        
        $name = $_POST['Name'];
        
        $html = <<<HEREDOC
            username : $Name <br>
        HEREDOC;  
        file_put_contents('newPage.php', $html); header('location: newPage.php'); exit;

        Something like this maybe

          I'm headed out to lunch. I will try it when I get back.

            Could of had sushi, decided to have a western skillet instead.

              Ok, so I currently have this, but when I refresh the page, it makes the new page which isn't what I want.

              PHP:

              <?php
              $content = $_GET["content"];
              $file = uniqid() . ".php";
              file_put_contents($file, $content);
              echo $file;
              ?>

              HTML:

              <button onclick="makePage()">click</button>
              <script src="makePage.js">
              </script>
              

              JS:

              function makePage(){
                  var xmlhttp = new XMLHttpRequest();
                  xmlhttp.onreadystatechange = function(){
                  if(xmlhttp.readyState==4 && xmlhttp.status==200)
                      alert("webpage " + xmlhttp.responseText + " was successfully created!");
                  }
                  var content = "<html><head><meta charset=\"utf-8\" /> </head><body>new website<script>alert(\"test\")</script></body></html>";
                  xmlhttp.open("GET","home.php?content=" + content,true);
                  xmlhttp.send();
              }
              

                You wouldn't make actual files for each page. You would make logical pages and output the content using a single content page.

                You would use a database table to store the submitted form information, the user id, the generated unique id, and the date and time. The URL would be the content page name with a get parameter - ?id=unique_id_here

                The code for the content page would query for the database table row matching the $_GET['id'] value. The code would also check if the date and time has expired and output an appropriate response if it has.

                Your code to make the page should use a post method submission and the server-side code needs to test if a post method form was submitted before doing anything with the data and do a permission check to see if there is a currently logged in user.

                  But I do want to make actual pages.

                  I want the user to be able to share a link for another user to see the page if you get what I mean.

                    The suggested method does produce actual pages, they are just all output using a single .php file, and it does let you share the link to the page.

                    This method is how just about every web site you have ever visited works. For example, every different forum thread on phpbuilder.com is not a separate file. It's produced by one .php file that uses a get parameter on the end of the url that tells that one .php file what content to display. You can share the url/link of any page on this forum with anyone and they can use that url/link to view that page on the forum.

                      Concur. For example, at work:

                      https://www.ombe.com/listing/646/Get-Help-Placing-An-Ad
                      https://www.ombe.com/listing/1707439/Canon-MF216n-imageCLASS-All-in-One-Laser-AirPrint-Printer

                      Same page, "listing", which is a PHP script. The rest is URL magic*.

                      Here on PHPBuilder:

                      http://board.phpbuilder.com/showthread.php?10395147-How-to-create-a-new-PHP-page-when-button-is-clicked
                      http://board.phpbuilder.com/showthread.php?10395149-RESOLVED-Mind-boggling-recursion-script!-Help!!

                      Same page, "showthread.php", which is a PHP script. The URL magic there is pretty obvious; the query string contains the number of the thread in the thread table of the vBulletin database. Now, to say that "showthread.php" is a single PHP script is a bit of a misnomer as there are lots of dependencies called via include() and require(), but pbismad is quite correct. You don't want to generate new PHP files. You want one file to generate lots of views.

                      Now, to go back to OMBE, we actually have several PHP pages: listing, category, categoryfilter, search, etc. Each one does something slightly different. But we have at present about 150K products, and I can absolutely guarantee I don't have 600,000 pages on our server(s).

                      *one way to do this 'magic' is Apache's mod_rewrite. There are some others, too.

                        Write a Reply...