Firstly I know there are probably better ways to do this but I need to include my links within a text file.
I required the following file first in php:
config.php
Code:
<?PHP
// Inialize session
ob_start();
session_start();
// Create a function to shorten code on other pages to check if SESSION isset
function loggedin() {
if (isset($_SESSION['user_id'])) {
return true;
}
else {
return false;
}
}
function getuserinfo($field) {
$query = "SELECT $field FROM tb_user WHERE id ='".$_SESSION['user_id']."'";
if ($result = mysql_query($query)) {
if ($query_result = mysql_result($result, 0, $field)) {
return $query_result;
}
}
}
?>
The problem is the PHP code next to Welcome does not display.
For that, you need to change the extension of that file to PHP. Otherwise, you'd need to configure your server to parse php code in txt file (which is not recommended)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
First of all, using .txt extension for PHP files is bad practice. Anybody can directly access it via HTTP and see the source code.
Secondly, debugging is a logical process, just like coding. If you dont get something as expected, follow the path and echo some variables and find out the exact reason. Here you could simply print_r($_SESSION) and see what are the variables it is having. Then if needed, echo the $query, verify if it goes into the if condition and print_r the $result and so on. There is no magic, use common sense and logic.
First of all, using .txt extension for PHP files is bad practice. Anybody can directly access it via HTTP and see the source code.
Secondly, debugging is a logical process, just like coding. If you dont get something as expected, follow the path and echo some variables and find out the exact reason. Here you could simply print_r($_SESSION) and see what are the variables it is having. Then if needed, echo the $query, verify if it goes into the if condition and print_r the $result and so on. There is no magic, use common sense and logic.
For someone to access it via HTTP they need to know the name of the file, which is hidden by the php part of the code.
Including as a .txt file is very handy for .css code, menus and other items that can be written verbatim to a page, as that is
what happens with an included .txt file.