...

View Full Version : chnaging content area



runnerjp
02-14-2008, 11:17 AM
hey guys... i wanna keep my main page the same but in the text area change the text depedning on the page

i thought about using something like

<?
if (file_exists($content)) {
include($content);
} else {?>
on index.php

then on the pages where the content is add $content="name.php";

i did this to show what i mean... i just wanna chnage data in contant chnage here area


-----------------------
| header |
| |
-----------------------
| | |
| | |
| | content |
| menu | change |
| | here |
| | |
------------------------

mlseim
02-14-2008, 01:33 PM
What you're doing is fine ...

Define $content yourself ...

DO NOT DO ANYTHING LIKE THIS:

<?
$content=$_GET['content'];
if (file_exists($content)) {
include($content);
} else {?>

That opens it up for any spammer or hacker to
put in their own URLs.


DO SOMETHING LIKE THIS INSTEAD ...
Your content is text files, or files stored in MySQL.

Here's what the URL looks like.
mywebsite.com/page.php?p=2

<?
$page=$_GET['p'];
$content = "page".$page.".txt";
if (file_exists($content)) {
include($content);
} else {?>

That way, you are controlling the content file, not the user.

Your file (such as "page12.txt") can also have PHP scripting in it.

rafiki
02-14-2008, 01:43 PM
iframe?

mlseim
02-14-2008, 01:45 PM
He didn't mention if a refresh is OK or not.
<iframe> would be best if no refresh is wanted.
(better than Javascripting).

aedrin
02-14-2008, 03:42 PM
No, an IFrame would not be helpful here.

This is just a basic template with a changing content area (as the subject mentions).

Andrew Johnson
02-14-2008, 03:47 PM
Ew, Iframes are never the way to go.

Why not just define which pages you want to use? EG:



<?php

if ($_GET["page"] == "about")
include("about.php");
elseif ($_GET["page"] == "contact")
include("contact.php");
elseif ($_GET["page"] == "services")
include("services.php");
else
include("home.php");

?>


What I like about this is that since it's on a template you only have to change it in one place, also take note of the else include("home.php"); because that means if the user goes to either page.php or page.php?page=anything-not-defined then they get the home page.

aedrin
02-14-2008, 03:48 PM
if ($_GET["page"] == "about")
include("about.php");
elseif ($_GET["page"] == "contact")
include("contact.php");

Do realize that this is an inefficient setup. And the whole point of a programming language is to make it easier for you to make. Otherwise we might as well just stick with HTML. ;)

Check my suggestion on this thread: http://www.codingforums.com/showthread.php?t=133261

Andrew Johnson
02-14-2008, 03:53 PM
So you're saying what? Put them into an array instead of listing them? Your linked code doesn't have all the same functionality either.

*This text removed by moderator*

aedrin
02-14-2008, 04:04 PM
Ignore the hidden nav section code.



$section = $_GET['section'];
$file = 'includes/'.$section.'.php';
if (file_exists($file)) {
include $file;
}


This doesn't require updating every time you add a page while still being secure enough (although you should probably filter $section so that it only has numbers and letters).

mlseim
02-14-2008, 04:13 PM
<iframes> have nothing to do with what content to appear ...
the iframe would be for changing the content in one section
without refreshing the whole page. He didn't specify if the
page can or cannot be refreshed.

The "include" issue can be anything really ... just so it's
protected from injection.

aedrin
02-14-2008, 04:15 PM
Correct, refreshing or not was not mentioned. Though it's simpler to use the include construct.

runnerjp
02-14-2008, 04:33 PM
wow ok im a little confused at the moment with all the replys lol

i want it so if a go to www.mypage.com/profile.php then tho profile will be shown on the content area

or www.mypage.com/about.php then about would be shown in content area


-----------------------
| header |
| |
-----------------------
| | |
| | |
| | content |
| menu | change |
| | here |
| | |
------------------------

aedrin
02-14-2008, 04:35 PM
Read my code suggestion.

runnerjp
02-14-2008, 04:37 PM
humm ok could you explain a little more hwo it works if that ok im alittle confused by it

aedrin
02-14-2008, 04:40 PM
index.php


include 'header.php';

if (isset($_GET['section'])) {
$section = $_GET['section'];
} else $section = 'home';

$file = 'includes/'.$section.'.php';
if (file_exists($file)) {
include $file;
}

include 'footer.php';


You'd call each page like this:

index.php?section=home
index.php?section=about

Etc.

So in the end you'd need to have index.php, header.php, footer.php, a folder called 'includes' and in there you'd place all the different pages such as about.php, home.php, etc.

runnerjp
02-14-2008, 05:05 PM
ok so would i make my link to index.php?section=about


and
if (isset($_GET['section'])) {
$section = $_GET['section'];
} else $section = 'home';

$file = 'includes/'.$section.'.php';
if (file_exists($file)) {
include $file;
}

would get the data from include file from about.php ??

aedrin
02-14-2008, 05:09 PM
Basically.

runnerjp
02-14-2008, 05:36 PM
ok i used this


<?php if (isset($_GET['section'])) {
$section = $_GET['section'];
} else $section = 'main';

$file = 'includes/'.$section.'.php';
if (file_exists($file)) {
include $file;
} ?>


and added includes/main.php

no main shows up ??

even when i try http://runningprofiles.com/members/index.php?section=main

how comes??

aedrin
02-14-2008, 05:40 PM
Turn on error reporting.

runnerjp
02-14-2008, 05:44 PM
hummm how lol

aedrin
02-14-2008, 05:46 PM
I can't tell you step by step how to do everything. I'm here to point you in the general direction of a solution.

Use a search engine.

mlseim
02-14-2008, 06:23 PM
Show us the script called "index.php" in your members directory.

runnerjp
02-14-2008, 08:17 PM
this is the index.php
<?php
session_start();
require_once '../settings.php';
checkLogin ('1 2');
?><style type="text/css">
<!--
body {
margin-left: 1px;
margin-top: 1px;
margin-right: 1px;
margin-bottom: 1px;
}
-->
</style>
<?php include ("../header.php"); ?>

<table colspan='0' width="100%" cellpadding="0" bgcolor="#FFFFFF">
<tr>
<td width="13%" height="505" align="center" valign="top"><table width="100%" align="center" bgcolor="#D6E0E0">
<tr>
<td height="496" colspan="2" bgcolor="#D6E0E0">&nbsp;</td>
</tr>


</table></td>
<td width="87%" align="center" valign="top">

<?php
if (isset($_GET['section'])) {
$section = $_GET['section'];
} else {
$section = 'main';
}
$file = "includes/".$section.".php";
if (file_exists($file)) {
require($file);
} ?>
</td>
</tr>

</table></td>
</tr>
</table>

and this is main.php


<td width="87%" align="center" valign="top"><p style="font-style: italic">&nbsp;</p>
<p align="center" style="font-style: italic"><table width="100%" >
<tr>
<td>&nbsp;</td>
<td><a href="test/update.php">update profile</td>
<td><a href="../logout.php">logout</td>
</tr>
<tr>
<td><a href="<?php echo get_username($_SESSION['user_id']);?>">MyProfile</a>.</td>


</tr>
</table>

mlseim
02-15-2008, 02:52 AM
I'm looking all over for "main.php" using your URL: http://runningprofiles.com/index.php

I can't find it ... are you sure your paths are correct?
../header.php exists

includes/main.php does not exist
members/includes/main.php does not exist

prove to us you are using the correct pathnames.

runnerjp
02-15-2008, 10:37 AM
ok done it http://runningprofiles.com/members/include/main.php

but for some reason every then goes to the far right hand side :S

code is same as provided before... i dont understand why as it should be dine :S

http://runningprofiles.com/images/error.jpg

runnerjp
02-15-2008, 11:43 AM
ah ok sorted it out...

ty for your help guys!!!

rafiki
02-15-2008, 11:43 AM
all to undefined function get_username() in /home/runningp/public_html/members/include/main.php on line 1

runnerjp
02-15-2008, 12:01 PM
ok got new error


<?php
session_start();
require_once '../settings.php';?>
<?

$query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1";
if ($result = mysql_query($query)){
if (mysql_num_rows($result)) {
$array = mysql_fetch_assoc($result);
$pemail = $array['Email'];
$puser = $array['Username'];
$pid = $array['ID'];
$pfirst_name = $array['first_name'];
$plast_name = $array['last_name'];
$pabout_me = $array['about_me'];
$pevents = $array['events'];



$sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1";
?>
<table width="100&#37;">
<tr>
<td colspan="2"><div align="center">Welcome <?php echo $puser; ?> </div></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="50%"><a href="<?php echo get_username($_SESSION['user_id']);?>">MyProfile</a></td>
<td width="50%"><a href="?section=uploader">change profile picture</a></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</table>

its strange because without

$query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1";
if ($result = mysql_query($query)){
if (mysql_num_rows($result)) {
$array = mysql_fetch_assoc($result);
$pemail = $array['Email'];
$puser = $array['Username'];
$pid = $array['ID'];
$pfirst_name = $array['first_name'];
$plast_name = $array['last_name'];
$pabout_me = $array['about_me'];
$pevents = $array['events'];



$sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1";
?>
it shows the table and data but with it i get blank page :S


the underfined function is fine... its just because you are on a TEST page where its not implamented into my user system yet

abduraooft
02-15-2008, 02:16 PM
if ($result = mysql_query($query)){
if (mysql_num_rows($result)) {
There are two opening curly braces, guess you missed to close them. Have really turned on the error reporting?

Deacon Frost
02-15-2008, 02:29 PM
Yeah, replace them with ;.

and...



Warning: require_once(../settings.php) [function.require-once]: failed to open stream: No such file or directory in /home/runningp/public_html/members/include/main.php on line 3

Fatal error: require_once() [function.require]: Failed opening required '../settings.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/runningp/public_html/members/include/main.php on line 3

That sounds like the directory to the file is wrong O.o.


And might I suggest the no-tables policy ;)!

mlseim
02-15-2008, 08:28 PM
Paths are usually the most common problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum