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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.