0

How would i make a 3 page website in 1 script using php? Example. There are sections that are fun, boring, and evil. And i want to be able to edit and create the website all in one page. I know its possible but i do not know how. Please help

2
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by tcollins412
0

Well, the easiest way would be to use the $_GET and a switch case statement.

Something like. . .

<!-- Header Stuff here -->

<?php
$here=$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
if (isset($_GET['page']))
 {
 $page=$_GET['page'];
 switch ($page)
  {
  case "fun":
   echo "This is the fun page.";
   // You said you wanted them all in one page, but you could also. . .
   include("fun.php");
   break;
  case "boring":
   echo "This is the boring page.";
   break;
  case "evil":
   echo "This is the evil page.";
   break;
  default:
   echo "Which page would you like?<br />";
   echo "<a href='$here?page=fun'>[FUN]</a> | ";
   echo "<a href='$here?page=boring'>[BORING]</a> | ";
   echo "<a href='$here?page=evil'>[EVIL]</a>";
  }
 }
?>

Something like that. With a little extra elbow grease you could use the POST method or you could even use javascript.

<script>
function selectPage(what)
 {
 var page = document.getElementById(what);
 document.getElementById('fun').style.visibility = 'hidden';
 document.getElementById('boring').style.visibility = 'hidden';
 document.getElementById('evil').style.visibility = 'hidden';
 page.style.visibility = 'visible';
 }
</script>
Which page would you like?<br />
<a href="#" onclick="selectPage('fun')">[FUN]</a> | 
<a href="#" onclick="selectPage('boring')">[BORING]</a> | 
<a href="#" onclick="selectPage('evil')">[EVIL]</a>

<div id='fun' style='visibility: hidden;'>
This is the fun page.
</div>
<div id='boring' style='visibility: hidden;'>
This is the boring page.
</div>
<div id='evil' style='visibility: hidden;'>
This is the evil page.
</div>

I know my javascript is laughable, but you get the idea. :) The JS script turns on the visibility for the page passed through 'what'. The links pass the div name to the javascript, and at the bottom are the actual page divs.

I did a 10 page website all crammed into one file using the first method. http://placelogo.t35.com/index2.php code available upon request. :)

Edited by dietdew12z: too many smilies, I'm not that happy.

0

Neither of those is a standalone webpage. The header stuff is the <html><head></head><body> and the other tags that you normally have in a web page. The part I wrote would go in between the <body> and </body> tags. And still probably wouldn't work because I just wrote it off the top of my head(as an example).

I always assume that if someone is programming in PHP that they have a basic working knowledge of HTML as well. Hold on and I'll flesh the thing out and post it.

David

Edited by dietdew12z: n/a

0

Here's the PHP version.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>3 Pages in 1</title>
</head>
<body>
<?php
$thispage=$_SERVER['SCRIPT_NAME'];
echo "Which page would you like?<br />";
echo "<a href='$thispage?page=fun'>[FUN]</a> | ";
echo "<a href='$thispage?page=boring'>[BORING]</a> | ";
echo "<a href='$thispage?page=evil'>[EVIL]</a><br /><br />";

if (isset($_GET['page']))
 {
 $page=$_GET['page'];
 switch ($page)
  {
  case "fun":
   echo "<div style='color: Red; background-color: #ccccff; border: 8px dashed #ccffcc;";
	 echo " font-size: 36px; font-style: italic; font-family: Comic-sans, Tahoma, sans-serif;";
	 echo " width: 800px; height: 400px; text-align: center;'>";
	 echo "<br /><br /><br /><br />This is the fun page.";
	 echo "</div>";
   // You said you wanted them all in one page, but you could also. . .
   break;
  case "boring":
   echo "<div style='color: #444444; background-color: White; border: 1px solid #cccccc;";
	 echo " font-size: 14px; font-family: Arial, helvetica, sans-serif;";
	 echo " width: 800px; height: 400px; text-align: left;'>";
	 echo "This is the boring page.";
	 echo "</div>";
   break;
  case "evil":
   echo "<div style='color: Red; background-color: #000000; border: 18px solid Red;";
	 echo " font-size: 36px; font-weight: bold; font-family: Times New Roman, Tahoma, sans-serif;";
	 echo " width: 800px; height: 400px; text-align: right;'>";
	 echo "<br /><br />This is the evil page.";
	 echo "</div>";
   break;
  default:
  }
 }
?>
</body>
</html>

Yeah, sorry. I'm just in a bad mood because it's New Year's Eve and instead of out having fun I'm stuck here working on a web site I'll probably never get paid for. :(

Edited by dietdew12z: n/a

0

Here's the javascript version. Both of these were tested with Firefox 4.0 Beta 8 and I right justified the evil text because we all know right justified text is always used for evil purposes. :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>
</head>
<body>
<script>
function selectPage(what)
 {
 var page = document.getElementById(what);
 document.getElementById('fun').style.display = 'none';
 document.getElementById('boring').style.display = 'none';
 document.getElementById('evil').style.display = 'none';
 page.style.display = 'block';
 }
</script>
Which page would you like?<br />
<a href="#" onclick="selectPage('fun')">[FUN]</a> | 
<a href="#" onclick="selectPage('boring')">[BORING]</a> | 
<a href="#" onclick="selectPage('evil')">[EVIL]</a>
<br />
<br />
<div id='fun' style='display: none; color: Red; background-color: #ccccff; border: 8px dashed #ccffcc; font-size: 36px; font-style: italic; font-family: Comic-sans, Tahoma, sans-serif; width: 800px; height: 400px; text-align: center;'>
<br /><br /><br /><br />This is the fun page.
</div>

<div id='boring' style='display: none; color: #444444; background-color: White; border: 1px solid #cccccc; font-size: 14px; font-family: Arial, helvetica, sans-serif; width: 800px; height: 400px; text-align: left;'>
This is the boring page.
</div>

<div id='evil' style='display: none; color: Red; background-color: #000000; border: 18px solid Red; font-size: 36px; font-weight: bold; font-family: Times New Roman, Tahoma, sans-serif; width: 800px; height: 400px; text-align: right;'>
<br /><br />This is the evil page.
</div>

</body>
</html>
0

In the PHP version, Could I use header tags instead of a bunch of echoes? An what if I wanted to run a PHP script On the website

0

In the PHP version, Could I use header tags instead of a bunch of echoes?

Yes. If you move the HTML code inside the switch case statements, here's a non-working snippet.

<?php
if (isset($_GET['page']))
 {
 $page=$_GET['page'];
 switch ($page)
  {
  case "fun":
	     // ********** Page 'fun' ************
			 ?>  

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>3 Pages in 1</title>
<style>
.fun
 {
 color: Red;
 background-color: #ccccff;
 border: 8px dashed #ccffcc;
 font-size: 36px;
 font-style: italic;
 font-family: Comic-sans, Tahoma, sans-serif;
 width: 800px;
 height: 400px;
 text-align: center;
 }
</style>
</head>
<body>
<div style='>
<br /><br /><br /><br />
This is the fun page.
</div>


       <?php
   break;
  case "boring":
	     // ********** Page 'boring' ************
			 ?>

So you just turn the PHP off after the case statement and back on before the break; statement. Lather, rinse, repeat.

An what if I wanted to run a PHP script On the website

I can think of three different things this question could mean, but the answer to all three is yes. Yes if you call it from another script, yes if you call another script from within this one, and yes if you want to run inline script.

0

and also, when i go to a differant page using the php version, the WHICH PAGE WOULD YOU LIKE? thing stays. How would i make it so it dissapears?

0

How would I do an actual PHP script with this? Like passing a form and stuff like that?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.