Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    92
    Thanks
    38
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    92
    Thanks
    38
    Thanked 0 Times in 0 Posts
    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 />

  • #4
    New Coder
    Join Date
    Apr 2010
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    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

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    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.

  • Users who have thanked DrDOS for this post:

    hans_cellc (10-18-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •