Page 1 of 2

PHP Question please

Posted: Mon Mar 29, 2004 5:41 pm
by RavenMist
I am making awebsite, but i want it to be friendly with every one so no iframes
BUT!! i don;'t want to make a thousand pages with the same stuff and having to update all of them if i just need to do one little link...so whats the PHP of doing it so you only change the main body of text

thanks!!

Posted: Mon Mar 29, 2004 5:48 pm
by Illusionist
so whats the PHP of doing it so you only change the main body of text
I,
1) Did not understand that question, and
2) Did not understand a word you said in your above post, so
You should,
1) Re-ask your question, in regular english, and
2) Slow down when your making a post, and re-read it before you actually post it. Make sure that people can understand exactly what your talking about.

Posted: Mon Mar 29, 2004 5:49 pm
by Steveo31
You need case/switch and GET variables:

Code: Select all

<form action="" method="get">
	Go to Page: <input type="text" name="page">
</form>
And on whatever page you choose to have the action be...

Code: Select all

if(isset($_GET['page']){
	$page = $_GET['page'];
	switch($page){
		case 'home':
			echo 'This is the home page.';
			break;
		case 'other':
			echo 'this is another page..';
			break;
		}
}

?>

Posted: Mon Mar 29, 2004 5:49 pm
by PrObLeM
i suggest using includes and just include the data that is changing

http://us3.php.net/manual/en/function.include.php

also learn about $_GET[]

then you can do something like this
example of url. http://www.mypage.com/?page=news would include news.php
http://www.mypage.com/?page=news would inlclude staff.php


Code: Select all

switch($_GET['page'])
{
   default:
   case 'news':
      include('news.php');
   break;
   case 'staff':
    include('staff.php');
    break;
}

Posted: Mon Mar 29, 2004 5:50 pm
by RavenMist
hehehe

woops :oops:

thanks every one...sorry about that.. i am not that best at english since i am a 13 year old

Posted: Mon Mar 29, 2004 5:50 pm
by PrObLeM
oops Steveo31 we posted at the same time :)

Posted: Mon Mar 29, 2004 5:51 pm
by Steveo31
PrObLeM wrote:oops Steveo31 we posted at the same time :)
Hehe... yea. I think I was a split second before you :P
Illusionist wrote:
so whats the PHP of doing it so you only change the main body of text
I,
1) Did not understand that question, and
2) Did not understand a word you said in your above post, so
You should,
1) Re-ask your question, in regular english, and
2) Slow down when your making a post, and re-read it before you actually post it. Make sure that people can understand exactly what your talking about.
We seemed to understand, be nice.

Posted: Mon Mar 29, 2004 5:52 pm
by PrObLeM
oh i forgot to mention the linkes would look like this

Code: Select all

<a href="?page=news">News!</a> <br>
<a href="?page=staff">Staff!</a>

Posted: Mon Mar 29, 2004 5:54 pm
by PrObLeM
Steveo31 wrote: We seemed to understand, be nice.
Yea!

Posted: Mon Mar 29, 2004 5:54 pm
by Illusionist
its just me, i dont understand half sentences. Even if you are only 13, i think you should be able to put together a rather legible and fairly understandable sentence...

Posted: Mon Mar 29, 2004 5:54 pm
by Sybatical
simple php script:
PHP is basically the oposite of SSI, in a way. This time you make the layout first, then you add the content. This is much faster at loading than SSI aswell. If you want to learn PHP, then I suggest that you learn SSI first. If you know SSI, then this will be alot easier to understand. If you wish to continute, simply follow the steps below.

Step 1
First off, make sure your host supports PHP! Angelfire, Geocities and most other free hosts wont but there are some, such as Host Ultra (who suck anyway).

Step 2
Make a layout with no content in it (an empty content area).

Step 3
Look for the place in your html you want the content to appear at and insert the following code:
<?php include ("$id"); ?>

Step 4
Save that page as main.php

Step 5
Now you have to create a page with just content, and no layout. You can call it whatever you want. In this case, we called it linkus.txt

Step 6
Upload both of these pages to your host and type in this url, http://www.yourhost.com/main.php?page=linkus.txt
NOTE: Dont forget to replace http://www.yourhost.com/ with your hosts URL!

Step 7
Go to that page and check to see if it is working correctly. It should work first time if you followed the instructions correctly.

Posted: Mon Mar 29, 2004 5:58 pm
by RavenMist
I am dislexic
:p

<quote>
if(isset($_GET['page']){
$page = $_GET['page'];
switch($page){
case 'home':
echo 'This is the home page.';
break;
case 'other':
echo 'this is another page..';
break;
}
} </quote>

Now the part that says

<quote> case 'other':
echo 'this is another page..';
break; </quote> Is that actually nessary, like will i need to add that part there for every page i have?

Posted: Mon Mar 29, 2004 5:58 pm
by Illusionist
how is that supposed to work? Do you mind explaining how that will work?? Because i'll bet anything that it wont work, if you follow those steps.

Posted: Mon Mar 29, 2004 6:02 pm
by PrObLeM
theres only a small error in the steps

change
Step 3
Look for the place in your html you want the content to appear at and insert the following code:
<?php include ("$id"); ?>
TO
Step 3
Look for the place in your html you want the content to appear at and insert the following code:
<?php
if(isset($_GET['page'])
{
include ($_GET['page']);
}
?>
:!: BUT!!!WARNING that is very VERY INSECURE!!!! so watch out...!!!! :!:

Posted: Mon Mar 29, 2004 6:03 pm
by Illusionist
RavenMist, say you have 3 links:

Code: Select all

&lt;a href="?page=home"&gt;Home&lt;/a&gt;
&lt;a href="?page=downloads"&gt;Downloads&lt;/a&gt;
&lt;a href="?page=contact"&gt;Contact&lt;/a&gt;
Then your switch would look something like this:

Code: Select all

if(isset($_GET['page']){
  $page = $_GET['page'];
  switch($page){
    case 'home':
      echo 'This is the home page.';
      //or if you have a main homepage you can do like:
      //include("home.html");
    break;
    case 'downloads':
      echo 'this is downloads page..';
      //include("downloads.html");
    break;
    case 'contact':
      echo 'this is contact page.';
      //include("contact.html");
    break;
  }
}