Jump to content

include php file


raduenea

Recommended Posts

I want to include a php file after an succesfully login.

Let's suposed that I have a login form on index.php. If the login was ok I want to include a php file with some content instead of the login form.

Something like:

<?
if($_POST['ok']){
     require('content.php');
} else {
//login form
}
?>

 

It's ok to include in the code the name of the file that you have on server ? From security point of view.

 

Thanks

Link to comment
Share on other sites

no. the code that i mentioned is located in index.php

I don't want to make any redirect. Just to inclide the content.php file.

It's ok to include in that way ?

 

How other huge website include pages like this ?

 

Link to comment
Share on other sites

Typically login systems are a bit more complex, but this would be a very basic example:

 

<?php
if($_POST['login_attempt']){
    //Attempt Login
}

if($_SESSION['logged_in']){
    require('account.php');
} else{
    require('loginform.html');
}

Link to comment
Share on other sites

So if I want to include multiple php file using the link for exemple:

 

index.php?page=account

or

index.php?page=add

 

I can use:

<?php
if($_SESSION['logged_in']){
    require($_GET['page'] . '.php');
} else{
    require('loginform.html');
}

 

It's ok ?

 

Link to comment
Share on other sites

its not the end of the world, but it wouldn't take a genius to work out what was happening.

instead of calling it page for example call it something irrelevant. or pass a number that the receiving script can convert to a file with a switch statement for example.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.