how do i display data on a page from mysql


Posted on 16th Feb 2014 07:03 pm by admin

1 - do i use this code at the top of each of my page i wish to only alow access if there as been a session
Code: <?php
include_once 'Connect.php';
if (!is_authed())
{
die ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.');
}
?>

connect.php i use to conect to database this also does a included to functions.php

this is part of my functions.php
Code: function user_login($username, $password)
// Now encrypt the data to be stored in the session
$encrypted_id = md5($user['id']);
$encrypted_name = md5($user['username']);

// Store the data in the session
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name'] = $encrypted_name;
}

function is_authed()
{
// Check if the encrypted username is the same
// as the unencrypted one, if it is, it hasn't been changed
if (isset($_SESSION['username']) && (md5($_SESSION['username']) == $_SESSION['encrypted_name']))
{
return true;
}
else
{
return false;
}
}

lastly if i want do display info from the database where it matches the session being used
What code would if any would i use to compliment the code in the first question and what code would i enter into the table below
Code: <html>
<head></head>
<body>
<table>
<tr>
<td>feild1 from database here</td>
<td>feild2 from database here</td>
<td>feild3 from database here</td>
</tr>
</table>
</body>
</html>

No comments posted yet

Your Answer:

Login to answer
167 Like 30 Dislike
Previous forums Next forums
Other forums

restricting another login once you logout
Hello,

how can I restrict a page from login authenticating against info in a MySQL DB for a s

Help with forum quoting?
Hi im working on a forum and I have alomost finished it but i want a user quote system like twitter

using variables in another page
I have a test database set up on localhost. I have a form that I can type a name into, hit the butto

Parse Error Help
Hello, I got the parse error "Parse error: syntax error, unexpected ',' in register.php on line

VAT
how should I deal with VAT?

if I have a product that costs £5.00 and VAT @ 17.5% (£0.87

Add User script "Could not execute query"
This should be an easy script but I can't get it to run. Can someone please help me?

<

Script not running properly
Hello Everyone
This is a basic script for posting to a database. I'm not sure why it doesn't work

Parse Error
Hi Guys,

I have a function in my class which returns a string link variable. The problem is i

Does design fit in FPGA ?
Hi all,

I've made a large HCC-Design. Because of the program-size the compile process with th

Ajax Error since Upgrading to 3.5
Ever since upgrading my site to .NET 3.5 (I needed LINQ), I've been getting this annoying error on o

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash