Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
CJ Webmaster Forums Forum Index » PHP & MySQL

   
-HELP- PHP Short url .php?page=
View previous topic :: View next topic  
Author Message
horaz
New User


Joined: 24 Oct 2005
Posts: 4

Posted: Mon Oct 24, 2005 12:46 pm    Post subject: -HELP- PHP Short url .php?page=

I dont know how to start talking here Laughing

Well, I have website and all page created with pure html and also it has gallery images. I call this as STATIC WEBSITE, because its rare to update. Then on my website has lots of html files also deep subdirectory. Here is some my root of my site:

index.html
about.html
contact.html
faq.html
-
gallery/index.html
gallery/cat1/index.html
gallery/cat2/index.html
gallery/cat3/indexl.html
--
gallery/cat1/sub1/index.html
gallery/cat1/sub2/index.html
--
gallery/cat2/sub1/index.html
gallery/cat2/sub2/index.html
etc etc etc.....

If I want to go to spesific page, I should type long long address. And this make me bored. Sad
This is possible to handle with 1 PHP file script (or migh be more) to get more simple and easy, soo I just call on php file using this format:

index.php?
index.php?page=about
index.php?page=contact
index.php?page=faq
-
index.php?page=gallery&cat1=1
index.php?page=gallery&cat1=2
index.php?page=gallery&cat1=3

Or something like that.. Just want to make it more cool to show and more simple. I have read on the previous thread about :
<? include($_GET['page'].".html"); ?>

But I still got error when no spesific page call. Like, no such file or directory when i type default index.php Sad Also, I dont know if that code support for subfolder inside. Im not able to view index.php?page=gallery/index or index.php?page=gallery/cat1/index Sad

Please help me to break this out, and thanks for any help
Also, sorry for my English
Back to top
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1410
Location: Michigan

Posted: Mon Oct 24, 2005 1:09 pm    Post subject:

making a your website work in php is not as hard as some think

one file could do it but its much easier to use more than one to control the pages

now there are two ways i know of that will let you do this:

first way: create template files(header,footer,nav,ect) for the design part of the site, then make .htm files that contain the actual content of the site.

Code:
<?
include "header.htm";
include "nav.htm";
$p = $_GET['p'];
if (($p == "") or ($p == "index")){
include "index.htm";
}elseif ($p == "contact"){
include "contact";
}else{
echo "page not found.";
}
include "footer.php";
?>


that way is good but basic in concept

second way: draw out data from a DB(like mysql) this is what most people do when they use something like php to control their pages.

Code:
<?
include "header.htm";
include "nav.htm";
$p = $_GET['p'];
$query = mysql_query("select * from site where page='$p'") or die(mysql_error());
$result = mysql_fetch_array($query);
$num = mysql_num_rows($query);
if ($num == 0){
echo "Sorry but the page your looking does not exist.";
}
echo $result['title'];
echo "<br> $result['content']";
include "footer.php";
?>


both are basic examples on how to do this, but its pretty much the concept.
_________________
Admin of CJ-Design Forum
watch out spammers, I'm watching you!

offical rules:
http://www.cj-design.com/forum/viewtopic.php?t=2002

Elite Bulletin Board v0.5 try it out today!
http://www.elite-board.z42.us/

version 0.9 coming soon!
Back to top
horaz
New User


Joined: 24 Oct 2005
Posts: 4

Posted: Mon Oct 24, 2005 1:41 pm    Post subject:

I just tried this code, and this pretty.

But I have a little problem,
1. When I call this index.php its reply
Code:
Notice: Undefined index: p in /home/www/www.domain.com/index.php on line 2

2. I have problem with relative links. Im trying to add
Code:
}elseif ($p == "gallery"){
include "gallery/index.html";

and deeper subdirectory. And it wont load the images and CSS Sad

Any sollution?
Back to top
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1410
Location: Michigan

Posted: Mon Oct 24, 2005 6:09 pm    Post subject:

ignore the that error, its a error to say that $p hasnt been defined accurding to the server if you have access to the php.ini file, just disable that.

as for the gallery page part, i would suggest making that its own file. it will be much easier that way
_________________
Admin of CJ-Design Forum
watch out spammers, I'm watching you!

offical rules:
http://www.cj-design.com/forum/viewtopic.php?t=2002

Elite Bulletin Board v0.5 try it out today!
http://www.elite-board.z42.us/

version 0.9 coming soon!
Back to top
GodfatherUK
CJ-Design.com Moderator



Joined: 17 Sep 2004
Posts: 232
Location: UK

Posted: Tue Oct 25, 2005 7:02 pm    Post subject:

Here is another alternative,

Code:
                <?php

// Enable output buffering
// More info: http://www.php.net/ob_start
   ob_start();

// Define our array of allowed $_GET values
   $pass = array('index','about','contact');

// If the page is allowed, include it:
   if (in_array($_GET['page'], $pass)) {

$p = $_GET['page'];

if ($p = "index"){
include ($_SERVER['DOCUMENT_ROOT'] . '/index.php');
}
if ($p = "about"){
include ($_SERVER['DOCUMENT_ROOT'] . '/about.php');
}
if ($p = "contact"){
include ($_SERVER['DOCUMENT_ROOT'] . '/contact.php');
}
else {
echo "Oops! Something went wrong! Try again..";
}

   }
      
// If there is no $_GET['page'] defined, then serve the homepage:
   elseif (!isset($_GET['page'])) {
      include ($_SERVER['DOCUMENT_ROOT'] . '/index.php');
   }
   elseif ($_GET['page'] == "") {
      include ($_SERVER['DOCUMENT_ROOT'] . 'index.php');
   }

// If the page is not allowed, send them to an error page:
   else {
      // This includes the error page
         include ($_SERVER['DOCUMENT_ROOT'] . 'error.php');
   }

      ?>

_________________
GodfatherUK
CJ Designs Forum Moderator

"I dont think i am good at coding.. But i KNOW im good at helping"
Back to top
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1410
Location: Michigan

Posted: Wed Oct 26, 2005 12:28 am    Post subject:

thats a neat way as well

its all the same concept
_________________
Admin of CJ-Design Forum
watch out spammers, I'm watching you!

offical rules:
http://www.cj-design.com/forum/viewtopic.php?t=2002

Elite Bulletin Board v0.5 try it out today!
http://www.elite-board.z42.us/

version 0.9 coming soon!
Back to top
GodfatherUK
CJ-Design.com Moderator



Joined: 17 Sep 2004
Posts: 232
Location: UK

Posted: Wed Oct 26, 2005 2:23 pm    Post subject:

yep, three different ways to do pretty much the same thing lol.

Hopefully this is enough to help..
_________________
GodfatherUK
CJ Designs Forum Moderator

"I dont think i am good at coding.. But i KNOW im good at helping"
Back to top
horaz
New User


Joined: 24 Oct 2005
Posts: 4

Posted: Fri Oct 28, 2005 3:51 am    Post subject:

Wheewwww...

I should try this last one, hope this wont give me error messages on server

Eeerrmm.... I think, I should learn this language.
Thank you,

Oohh... Anyone know, where can I learn how to build PHP catalog. I mean, how to build web catalog?

Using pure html just waste my time, edited one file by one Sad Where should I start?

Thank you for help --Really Appreciate--
Back to top
PHPDUMMY
CJ-Design.com Moderator



Joined: 09 Mar 2005
Posts: 569
Location: South East Kentucky,U.S.A.

Posted: Fri Oct 28, 2005 4:49 am    Post subject:

http://www.php.net/
_________________
Cheers,
Danny
C-J Search Engine All Tidied Up V4.0http://www.cj-design.com/forum/viewtopic.php?t=1820

C-J Search Engine MySQL !http://www.cj-design.com/forum/viewtopic.php?t=1555
Back to top
horaz
New User


Joined: 24 Oct 2005
Posts: 4

Posted: Fri Oct 28, 2005 9:51 am    Post subject:

Whoaaaaaaahhhh....

php.net?? wheeeww..... to complicated, I mean, a site that offers step by step how to build that catalog.
Uhhmm... maybe you right, www.php.net the best place to learn, but sometimes i went there, its too confusing...

Is CJ offer tutorials like this??


O yahhh... I have problem with last scripts, I got nothing error on my site, but when I change page to [index.php?page=contact] or about or else, its stay to show always index page, I mean there's no changing.... always index page.

What wrong with that? or I have problem with my server?

Thank you...
Back to top
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1410
Location: Michigan

Posted: Fri Oct 28, 2005 4:47 pm    Post subject:

no james dont has any tutorials but i can direct you to some

http://phpfreaks.com

php.net will be useful for you once you have a good concept of php


if your still getting those notice errors, just disable them in your php.ini file, and if you dont have access to it, i think theres a way to disarm that error using .htaccess

but my example is pretty cut clear & dry
_________________
Admin of CJ-Design Forum
watch out spammers, I'm watching you!

offical rules:
http://www.cj-design.com/forum/viewtopic.php?t=2002

Elite Bulletin Board v0.5 try it out today!
http://www.elite-board.z42.us/

version 0.9 coming soon!
Back to top
PHPDUMMY
CJ-Design.com Moderator



Joined: 09 Mar 2005
Posts: 569
Location: South East Kentucky,U.S.A.

Posted: Thu Nov 03, 2005 12:14 pm    Post subject:

yeah , well give you tutorials , how much you paying for live tutorials ...........lmfao......hehehe ( sorry , i just had to....lol )
_________________
Cheers,
Danny
C-J Search Engine All Tidied Up V4.0http://www.cj-design.com/forum/viewtopic.php?t=1820

C-J Search Engine MySQL !http://www.cj-design.com/forum/viewtopic.php?t=1555
Back to top
Display posts from previous:   
       CJ Webmaster Forums Forum Index » PHP & MySQL All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
iCGstation v1.0 Template By Ray © 2003, 2004 iOptional, Mods by CJ Website Design