It may be that your 'problem' is more a project issue.
Note that your permission array does not form combinations, with this you need to get the 1st bar that corresponds to a file that will scan bar by bar with a series of if’s.
$permissao = array( 'home' , 'comer' , 'dormir' , '...' );
if(!isset($primeiraUrl) || $primeiraUrl == ''){
include("conteudos/home.php");
}elseif(isset($primeiraUrl) && in_array($primeiraUrl, $permissao)){
include("".$directorio."/".$primeiraUrl.".php");
}
This form is very poorly flexible, the ideal is to create a config file that abstracts the routes and a file to validate.
If the URL is http://exemplo.pt/empresa-x
, then your variable $primeiraUrl
will have the value of enterprise-x, and this is outside its rules in the array $permissao
.
A solution that would solve your problem would be to treat the exception as an ad page. Thus, the URL’s http://exemplo.pt/qualquer-nome-de-empresa
will be accepted and it will be up to the system to check whether the ad was found or not, and will continue to work for the other URL’s you have, like http://exemplo.pt/comer/
, http://exemplo.pt/dormir/
.
solution
if( ! isset( $primeiraUrl ) || $primeiraUrl == '' ) {
include 'conteudos/home.php';
} elseif( in_array( $primeiraUrl , $permissao ) ) {
include "{$directorio}/{$primeiraUrl}.php";
} else {
// $primeiraUrl não está no array, posso SUPOR que seja um anuncio
// include no arquivo que carrega o anuncio
// include 'anuncio.php';
}
advertising.php
Verifica no DB se `$primeiraUrl` corresponde a algum anúncio
caso contrário, você apresenta sua mensagem de erro.404
OBS, This solves the problem, but it’s not ideal. I recommend looking for routes in PHP
Updating
Doing the routing by .HTACCESS, you would have to define all possible routes, including the order, as in the example below.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# http://exemplo.pt/comer/
RewriteRule ^comer\/$ index.php?controller=comer&option=index [QSA,L]
# http://exemplo.pt/comer/camarao/
RewriteRule ^comer\/([a-zA-Z-0-9-_]+)\/ index.php?controller=comer&option=tipo&tipo=$1 [QSA,L]
# http://exemplo.pt/restaurante-do-joao/
RewriteRule ^([a-zA-Z-0-9-_]+)\.html index.php?controller=anuncio&option=$1 [QSA,L]
The advantage will be that you will not need PHP to combine the possible routes, combining input and output. You will receive via GET
the ready parameters.
Note that I alluded to an MVC-based system. Not being your case, then, controller
represents a physical file that will work with the option
. Everything will start by index.php
, then a superficial example would be:
To the input URL http://exemplo.pt/comer/restaurante-do-joao/
, you will have
$_GET['controller'] = 'anuncio'
$_GET['option'] = 'restaurante-do-joao'
In his index php. you do the proper checks - which I omitted - and have the corresponding file uploaded to the controller:
//include anuncio.php
include $_GET['controller'] . 'php';
In the case of the example, it will be loaded advertising.php, and in it you use $_GET['option']
to find the company name.
Are the paths (parameters) already being correctly added to your database? (Low box, no accents, use of hyphen to separate words, etc)
– user20212
yes I am no longer able to incorporate the pages now
– César Sousa
I don’t know where your problem really is - whether it’s in creating rules, url’s, uploading the content of the establishment... Could you provide more details?
– Papa Charlie
The context is very vague. Describe better, put more details of where your difficulty is.
– Daniel Omine
I’ll explain better what the problem is
– César Sousa
You should use your htaccess file to create URL rewriting rules.
– user20212
How do I want the url name to come from the database not to do from the.php function file with htaccess just like this one ?
– César Sousa
Can you give me a more precise help so I know how to do it ?
– César Sousa
I still don’t understand the problem. You’re having trouble creating routes or links?
– Papa Charlie
I’m having a hard time creating the routes
– César Sousa
Somebody give me a little help if possible
– César Sousa
is that you’re trying to get $_GET.... you have to use $_SERVER['REQUEST_URI'] ...
– Daniel Omine