Help mij met dit stukje PHP

Gestart doorSebastiaanh5 reacties42 weergaven

6 berichten · pagina 1 van 1

Sebastiaanh

Lid · Topicstarter

Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Beste,

Ik ben op dit moment bezig met een website. Echter heb ik 1 vraagje;

Hoe zorg ik ervoor dat, als de pagina niet bestaat, hij geen error aangeeft, maar iets aangeeft als:

"Deze pagina bestaat niet!"

Dit is mijn code;

[COLOR= #0000BB]<?php
    $p[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]];[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]])) {[/COLOR]
      [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/home.php[/COLOR][COLOR= #007700]);
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$p[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700]);
    }[/COLOR]
?>
0
Berichten
994
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]])){[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700])){[/COLOR]
        [URL="http://www.php.net/require"]require[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$p[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700]);
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/require"]require[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]error/404.php[/COLOR][COLOR= #007700]);
    }
}[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/require"]require[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]page/home.php[/COLOR][COLOR= #007700]);
}[/COLOR]
?>
0
Berichten
15.446
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000].php[/COLOR][COLOR= #007700]))[/COLOR]
            [URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]pages/[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000].php[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/else"]else[/URL]
            [URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]pages/404.php[/COLOR][COLOR= #007700];
        
    }[/COLOR]
    
    [URL="http://www.php.net/else"]else[/URL]
        [URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]pages/home.php[/COLOR][COLOR= #007700];[/COLOR]
?>


en dan zelf een 404.php pagina maken met de tekst "deze pagina bestaat niet".
0
Sebastiaanh

Lid · Topicstarter

Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt! biggrin
0
Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sebastiaanh schreef:
Beste,

Ik ben op dit moment bezig met een website. Echter heb ik 1 vraagje;

Hoe zorg ik ervoor dat, als de pagina niet bestaat, hij geen error aangeeft, maar iets aangeeft als:

"Deze pagina bestaat niet!"

Dit is mijn code;
[COLOR= #0000BB]<?php
    $p[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]];[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]p[/COLOR][COLOR= #007700]])) {[/COLOR]
      [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/home.php[/COLOR][COLOR= #007700]);
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]pages/[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$p[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000].php[/COLOR][COLOR= #007700]);
    }[/COLOR]
?>


als deze code zou werken was hij niet veilig.
de andere zijn wel goed.
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Gebruik liever require dan include als je de paginas écht sowieso wilt oproepen.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren