Page 1 of 1

PHP & links

Posted: Mon Dec 08, 2003 10:26 am
by wat
Hi there

I would like to learn php and I started to read some of the tutorials available on the web. It’s kind though and it is not sinking in. Would anybody have the time to explain the following to me:

How would I for instance change content of the table cells using php? Please see the mock up I have set up:

http://www21.brinkster.com/lusatia/test/


Any help would be much appreciated as well as code explanation.

Posted: Mon Dec 08, 2003 1:03 pm
by Gen-ik
The best way to do it would be to use a collection of different files and then load the ones you need into the page.

Here's a very simple example just to get you started.

Code: Select all

<?php

if(isset($_GET["stuff"]))
{
     $file = $_GET["stuff"].".php";
}

?>

<table>
<tr>
<td>
<?php require($file) ?>
</td>
</tr>
</table>

<a href="?stuff=one">load stuff one</a><br />
<a href="?stuff=two">load stuff two</a>
That's as basic as it gets really.

If you click on 'load stuff one' then the contents of a file called 'one.php' will be loaded into the <td>.
If you click on 'load stuff two' then the contents of a file called 'two.php' will be loaded in to the <td>.

After looking at your example page though I think you might need to use a couple of $_SESSION variables.. which is something you will need to look up and study. Try taking a look at http://www.php.net

Posted: Tue Dec 09, 2003 9:21 am
by wat
One person wrote this code for me. Which I can understand, but the problem starts when I want to change content of for instance 3 cells in the table with one link as illustrated in my example

http://www21.brinkster.com/lusatia/test/

Would anybody show me how to do this with a code exapmle.

Thanks a bunch!


<body>
<?php
// find the name of the include file for the main section
$main = (isset($_GET['main']))? $_GET['main'] : "main";

$mainContent = "$main.php"; // This can be any file extension you want, as long as they're all the same
?>
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr height=131>
<td colspan=2 class='top' valign='bottom'>
<?php include('top.php') ?>
</td>
</tr>
<tr>
<td class='nav' width=125 valign='top'>
<?php include('nav.php') ?>
</td>
<td class='right' valign='top'>&nbsp;
<?php include($mainContent) ?>
</td>
</tr>
</table>
</body>

Posted: Tue Dec 09, 2003 10:35 am
by m3mn0n
I just want to note you should never have page names as variables in a URL without adding something that will make sure the file is within your folder only.

Otherwise you might be susceptible to hackers remotely linking their evil scripts into your site for execution.

Yes this isn't as big a concern as it would be with open source applications, but nonetheless it's still is a concern.

Code: Select all

<?php
if(isset($_GET["stuff"])) 
{ 
     $file = "./".$_GET["stuff"].".php"; 
}
?>

Posted: Tue Dec 09, 2003 12:34 pm
by Weirdan
probably even better way would be:

Code: Select all

if(isset($_GET["stuff"])) 
{ 
     $file = "./".basename($_GET["stuff"]).".php"; 
}
because it prevents the traversals:

Code: Select all

http://yoursite.com/yourscript.php?stuff=../inc/config

Posted: Wed Dec 10, 2003 10:26 am
by wat
Thanks for your reply.

I am starting out with php so basic things some time seem to me like black magic.

Having this code (see below), how would I write a basic link using php to change content of 3 cells at once? Let say I have the following files:

nav.php, top.php and main.php

Huge thanks for your help and your patiance :oops:


PHP:--------------------------------------------------------------------------------

<body>
<?php
// find the name of the include file for the main section
$main = (isset($_GET['main']))? $_GET['main'] : "main";
$nav = (isset($_GET['nav'])) ? $_GET['nav'] : "nav";
$top = (isset($_GET['top'])) ? $_GET['top'] : "top";
$mid = (isset($_GET['mid'])) ? $_GET['mid'] : "mid";

$mainContent = "$main.php"; // This can be any file extension you want, as long as they're all the same
$midBarContent = "$mid.php";
$navContent = "$nav.php";
$topContent = "$top.php";
?>
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr height=131>
<td colspan=2 class='top' valign='bottom'>
<?php include($topContent) ?>
</td>
</tr>
<tr height=131>
<td colspan=2 class='???' valign='bottom'>
<?php include($midBarContent) ?>
</td>
</tr>
<tr>
<td class='nav' width=125 valign='top'>
<?php include($navContent) ?>
</td>
<td class='right' valign='top'>
<?php include($mainContent) ?>
</td>
</tr>
</table>
</body>
--------------------------------------------------------------------------------