Php friendly urls

Asked

Viewed 270 times

0

Hello, my question is the following: I am developing a system in HTML and PHP, I have been researching on friendly Urls, some friends have indicated me to use because according to them the main page would not be updated every time I access a link. Well, I followed many tutorials, I made dozens of different ways that I found on the web and I believe it is not working. To test I am using a function that UPDATE in a mysql database at the top of the page, that is, every time that every page is updated it adds +1 counting the return of the bank +1. I wonder how I do so when I call another page on a link just search the content and do not refresh on every page

follow this tutorial https://www.youtube.com/watch?v=hCnBrQ1fekA

follows the code I made:

.htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

config.inc.php

<?php
define('HOME', 'http://localhost/testeAmigo/');
define('THEME','paginas');

define('INCLUDE_PATH', HOME.THEME);
define('REQUIRE_PATH',THEME);

$getUrl = strip_tags(trim(filter_input(INPUT_GET, 'url', FILTER_DEFAULT)));
$setUrl = (empty($getUrl) ? 'index' : $getUrl);
$Url = explode('/', $setUrl);
//var_dump($Url);
 ?>

index php.

<?php
require 'config.inc.php';
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Teste Urls Amigáveis</title>
</head>
<body>
  <header>
    <nav>
      <ul>
        <li><a href="?url=home"> Home</a></li>
        <li><a href="?url=contato"> Contato</a></li>
        <li><a href="?url=sobre"> Sobre</a></li>
      </ul>
    </nav>
  </header>
  <hr>

  <!--CONTEUDO -->
  <?php
  $Url [1] = (empty($Url[1]) ? null : $Url[1]);
  if(file_exists(REQUIRE_PATH . '/' . $Url[0] . '.php')):
    require REQUIRE_PATH . '/' . $Url[0] . '.php';
    elseif(file_exists(REQUIRE_PATH . '/' . $Url[0] . '/' . $Url[1] . '.php')):
      require REQUIRE_PATH . '/' . $Url[0] . '/' . $Url[1] . '.php';
    else:
      require REQUIRE_PATH . '/404.php';
    endif;
    ?>
    <!--CONTEUDO -->
    <hr>
    <footer>
      <center>
        <label>www.teste123.com</label>
      </center>

    </footer>
  </body>
  </html>

In addition there is the folder 'pagians' which contains the home.php files, contact,php and about.php.

  • Do you want to update the content without updating the page? That’s it?

  • Yes, for example: I have my html(index.php) structure with the CSS and JS(tags) calls, in the middle of the page I have a div content that calls the file as I click on the liks in the menu, only every time I click on a link it reloads the whole page. I was referred to the friendly Urls, but I don’t think it would be ideal for this.

  • No Rafa, to do this you can use AJAX JQUERY. Gives a search. There is plenty of content about it here in Stack and also in google.

  • You need to use Javascript either pure or with JQUERY, because it will identify an EVENT (click) and then you will update a div or content along with php. The key word is ajax.

  • I will search Andrei Thank you very much

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.