Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2012, 08:04 AM   PM User | #1
hans_cellc
New Coder

 
Join Date: Oct 2011
Posts: 92
Thanks: 38
Thanked 0 Times in 0 Posts
hans_cellc is an unknown quantity at this point
include text file

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;
			}
		}
	}
	
	
?>
Then I include the
header_secure.txt
Code:
<h1 style="font-size: 400%; font-family: Forte, Verdana, Arial, Helvetica, sans-serif; color: #000000; margin-top: -7px;" align="center">CONSOLE GAMES FOR SALE</h1>
<h1 style="font-size: 300%; font-family: Forte, Verdana, Arial, Helvetica, sans-serif; color: #FF0000; margin-top: -20px;" align="center">PS2 - PS3 - Wii - X-BOX</h1><br />

<!-- Links -->
<table width="100%" style = "margin-top: -25px;">
<tr align="center"><td ><h3 style = "margin-top: -5px; margin-bottom: 1px;"><a href="http://127.0.0.1/exam/index.php" name="top">Home Page</a> | 
<a href="http://127.0.0.1/exam/insert.php">Insert</a> | <a href="http://127.0.0.1/exam/list.php">List</a>| 
<a href="http://127.0.0.1/exam/source_code.php">Source Codes</a> | 
Welcome: <strong>
<?PHP 
$firstname = getuserinfo('name'); 
$surname = getuserinfo('surname'); 
echo "$firstname $surname";
?>
</strong> | <a href="logout.php">Logout</a></h3></td></tr></table>

<h2 style="color: yellow; font-family: Verdana, Arial, Helvetica, sans-serif;" align="center">Members Zone</h2>

<!-- Insert a horizontal line (ruler) -->
<hr /><br />
The problem is the PHP code next to Welcome does not display. Please help.
hans_cellc is offline   Reply With Quote
Old 10-18-2012, 10:05 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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)
abduraooft is offline   Reply With Quote
Old 10-18-2012, 12:06 PM   PM User | #3
hans_cellc
New Coder

 
Join Date: Oct 2011
Posts: 92
Thanks: 38
Thanked 0 Times in 0 Posts
hans_cellc is an unknown quantity at this point
Got it sorted thanks still in a text file, this is what I did.

For some reason it does echo the SESSION in the PHP code and all I did was to create a SESSION with the name and surname and it works.

Below my code:
header_secure.txt
Code:
<h1 style="font-size: 400%; font-family: Forte, Verdana, Arial, Helvetica, sans-serif; color: #000000; margin-top: -7px;" align="center">CONSOLE GAMES FOR SALE</h1>
<h1 style="font-size: 300%; font-family: Forte, Verdana, Arial, Helvetica, sans-serif; color: #FF0000; margin-top: -20px;" align="center">PS2 - PS3 - Wii - X-BOX</h1><br />

<!-- Links -->
<table width="100%" style = "margin-top: -25px;">
<tr align="center"><td ><h3 style = "margin-top: -5px; margin-bottom: 1px;"><a href="http://127.0.0.1/exam/index.php" name="top">Home Page</a> | 
<a href="http://127.0.0.1/exam/insert.php">Insert</a> | <a href="http://127.0.0.1/exam/list.php">List</a>| 
<a href="http://127.0.0.1/exam/source_code.php">Source Codes</a> | Welcome: <strong><?PHP echo $_SESSION['userlogin']; ?></strong>
 | <a href="logout.php">Logout</a></h3></td></tr></table>

<h2 style="color: yellow; font-family: Verdana, Arial, Helvetica, sans-serif;" align="center">Members Zone</h2>

<!-- Insert a horizontal line (ruler) -->
<hr /><br />
hans_cellc is offline   Reply With Quote
Old 10-18-2012, 01:10 PM   PM User | #4
alemcherry
New Coder

 
Join Date: Apr 2010
Posts: 55
Thanks: 0
Thanked 4 Times in 4 Posts
alemcherry is an unknown quantity at this point
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.
__________________
Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon
alemcherry is offline   Reply With Quote
Old 10-18-2012, 10:35 PM   PM User | #5
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,156
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
Quote:
Originally Posted by alemcherry View Post
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.
DrDOS is offline   Reply With Quote
Users who have thanked DrDOS for this post:
hans_cellc (10-18-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:05 AM.


Advertisement
Log in to turn off these ads.