5 Replies - 401 Views - Last Post: 02 October 2017 - 09:55 AM Rate Topic: -----

#1 Brian_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-October 17

How Do I Create a Vanity URL or New Page After Submit

Posted 01 October 2017 - 11:23 AM

Hello so I have a site setup to where users can submit projects and it adds it to a upload folder and the database for user download anyway I want to have it so once a user submits a new project / file it creates a URL like ď**sitename.com/projects.html?*projectname***Ē or something like that. My code is below. I donít even know where to start.

P.S Everything on my site works just need to learn how to create the url.

projects.html: Mainly used to display the recent projects.

<?php include("includes/header.php"); ?>

    <?php
    include_once 'dbconnect.php';
    
    // fetch files
    $sql = "select filename, title, description from tbl_files LIMIT 4";
    $result = mysqli_query($con, $sql);
    ?>
    
    
    <div id="container">
      <div class="wrapper">
        <div id="content">
          <h2>Recent Projects <button style="float: right;"><a href="new-project.html">New Project</a></button></h2>
          <p><table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>File Name</th>
    <th>Description</th>
                            <th>Download</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $i = 1;
                    while($row = mysqli_fetch_array($result)) { ?>
                    <tr>
                        <td><?php echo $i++; ?></td>
                        <td><?php echo $row['title']; ?></td>
    <td><?php echo $row['description']; ?></td>
                        <td><a href="uploads/<?php echo $row['filename']; ?>" download>Download</td>
                    </tr>
                    <?php } ?>
                    </tbody>
                </table>
    </div>
    </p>
        
        <div id="column">
          <div class="holder">
            <h2>Welcome!</h2>
            <ul id="latestnews">
              
              <li class="last"> <p><?php
        session_start();
       include_once "vendor/autoload.php";
        $page = new membership\Page(1);
        if ($page->isValid() == true){
             echo "Hello " . $_SESSION["username"] . "!<br /><br />
    
    <a href='logout.html'>Logout</a>\n";
            } elseif ($page->isValid() == false) { echo "<center>Please <a href='login.php'>Log in</a> to share projects.<br /> <a href='register.php'>Need A Account?</a></center>";}
    ?><br />
          </p>
        
        <br /></p>
              </li>
            </ul>
          </div>
        </div>
        <br class="clear" />
      </div>
    </div>
    
    <?php
    error_reporting(E_ALL & ~E_NOTICE);
    include('includes/memberlistconfig.php');
    
    // call this file only after database connection
    require_once 'functions.php';
    ?>
    
       
    <div id="container">
      <div class="wrapper">
        <div id="content">
          <h2>Categories</h2>
          <p>
            <div class="height20"></div>
            <?php echo $emsg; ?>
          
      <article>
              Click on one of the categories to see whatís inside.
              <ul>
                <?php
                $res = fetchCategoryTreeList();
                foreach ($res as $r) {
                  echo  $r;
                }
                ?>
              </ul>
             </article>
    </div></p>
    <br class="clear" />
      </div>
    </div>
    
      <?php include("includes/footer.php"); ?>



new-project.html: Allows used to upload a new project.



 <?php
    include_once('includes/header.php'); ?>
    <?php 
    include_once 'dbconnect.php';
    
    // fetch files
    $sql = "select filename from tbl_files";
    $result = mysqli_query($con, $sql);
    ?>
    <?php
    session_start();
    include_once "vendor/autoload.php";
    $page = new membership\Page(1);
    if ($page->isValid() == true) {
        ?>
    
        
        
    
    <div id="container">
      <div class="wrapper">
        <div id="content">
          <h2>New Project</h2>
          <p><center>
    
    <form action='upload.php' method='post' enctype='multipart/form-data'>
                            <legend>Select File to Upload:</legend>
                            <div class='form-group'>
    Title: <br /><input type='text' name='title' maxlength="255"/><br /><br />
    Description: <br /><textarea type='text' name='description' maxlength="2000"></textarea><br /><br />
    
                                <input type='file' name='file1' />
                            </div>
                            <div class='form-group'><br />
                                <input type='submit' name='submit' value='Upload' class='btn btn-info'/>
                            </div>
                            <?php if (isset($_GET['st'])) { ?>
                                <div class='alert alert-danger text-center'>
                                    <?php
                                    if ($_GET['st'] == "success") {
                                        echo "File Uploaded Successfully!";
                                    } else {
                                        echo 'Invalid File Extension!';
                                    }
                                    ?>
                                </div>
                            <?php } ?>
                        </form></center>
    
    </p><?php } ?>
    
    <br /></div>
    </p>
        
        <div id="column">
          <div class="holder">
            <h2>Project Upload Rules</h2>
            <ul id="latestnews">
              This is this rules you must follow for uploading a project.<br /><br />
     - You must own the project / script.<br />
     - Must be 100% clean / safe.<br />
     - Code must be easy to read.<br />
     - No outdated code.<br />
    <br />
    If you donít follow the rules your account who be banned. 
              <br />
          </p>
        
        <br /></p>
              </li>
            </ul>
          </div>
        </div>
        <br class="clear" />
      </div>
    </div>
    
    <?php include_once('includes/footer.php'); ?>



upload.php: This file uploads the info to the database.

<?php include('dbconnect.php'); ?>
    <?php
    //check if form is submitted
    if (isset($_POST['submit']))
    {
        $filename = $_FILES['file1']['name'];
    
        //upload file
        if($filename != '')
        {
            $ext = pathinfo($filename, PATHINFO_EXTENSION);
            $allowed = ['zip', 'rar', 'php', 'html', 'sql'];
        
            //check if file type is valid
            if (in_array($ext, $allowed))
            {
                // get last record id
                $sql = 'select max(id) as id from tbl_files';
                $result = mysqli_query($con, $sql);
                if (count($result) > 0)
                {
                    $row = mysqli_fetch_array($result);
                    $filename = ($row['id']+1) . '-' . $filename;
                }
                else
                    $filename = '1' . '-' . $filename;
    
                //set target directory
                $path = 'uploads/';
                    
                $created = @date('Y-m-d H:i:s');
                move_uploaded_file($_FILES['file1']['tmp_name'],($path . $filename));
                
    $title = '';
    if(!empty($_POST['title']))
    {
       $title = mysqli_real_escape_string($con, $_POST['title']);
    }
    $description = '';
    if(!empty($_POST['description']))
    {
       $description = mysqli_real_escape_string($con, $_POST['description']);
    }
                // insert file details into database
                $sql = "INSERT INTO tbl_files(filename, created, title, description) VALUES('$filename', '$created', '$title', '$description')";
                mysqli_query($con, $sql);
                header("Location: new-project.html?st=success");
            }
            else
            {
                header("Location: new-project.html?st=error");
            }
        }
        else
            header("Location: new-project.html");
    }
    ?>


Is This A Good Question/Topic? 0
  • +

Replies To: How Do I Create a Vanity URL or New Page After Submit

#2 Brian_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-October 17

Re: How Do I Create a Vanity URL or New Page After Submit

Posted 01 October 2017 - 01:31 PM

Why no help guys?
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3714
  • Posts: 13,467
  • Joined: 08-August 08

Re: How Do I Create a Vanity URL or New Page After Submit

Posted 01 October 2017 - 05:08 PM

Speaking for myself, when I see code that is wide open to SQL injection attacks because it's not using prepared statements, I move on.

It is 2017, not 2007!
Was This Post Helpful? 0
  • +
  • -

#4 Brian_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-October 17

Re: How Do I Create a Vanity URL or New Page After Submit

Posted 01 October 2017 - 05:13 PM

View PostCTphpnwb, on 01 October 2017 - 05:08 PM, said:

Speaking for myself, when I see code that is wide open to SQL injection attacks because it's not using prepared statements, I move on.

It is 2017, not 2007!


Well how do I convert it them?
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3714
  • Posts: 13,467
  • Joined: 08-August 08

Re: How Do I Create a Vanity URL or New Page After Submit

Posted 01 October 2017 - 06:57 PM

http://www.dreaminco...duction-to-pdo/

http://php.net/manua...-statements.php
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1828
  • View blog
  • Posts: 5,755
  • Joined: 15-January 14

Re: How Do I Create a Vanity URL or New Page After Submit

Posted 02 October 2017 - 09:55 AM

We're just a group of volunteers here trying to help people, if you don't get an answer after 2 hours on a Sunday afternoon it might just be because there's not many people here.

You don't create the URL, what you need to do is configure the server to handle those URLs. You don't have to register a URL or whatever on a web server, people can type in any URL to your server and your server will try to handle the request based on how it's configured. What you need to do is configure your server to use URL rewriting. When you use URL rewriting then you can set it to search for patterns in the URL and have those requests handled by a PHP script or something like that. So if you have it so that the URLs for projects point to a certain directory or something like that, then you can set up URL rewriting so that any requests to that directory go to a PHP script that can look up the project ID from the URL and get information about it from the database.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1