Jump to content

Recommended Posts

I am trying to make a website that lets me click a menu option and it just loads an html file into a window.

I have one right now, but there is a problem. When the page loads, the initial html file loads (main.html) But when I go to click a link, it keeps main.html instead of going where asked. However, it does show the correct address in the address bar.

 

 

here is what I have so far

 

<?php

  if (empty($page)) {

  $page = "main.html";

}

if (file_exists("$page")) {

  include("$page");

}

else {

  echo "<b>404</b> File not found.";

}

?>

 

Then the links are like this

index.php?page=main.html

 

 

Thanks for any help :)

Link to comment
https://forums.phpfreaks.com/topic/66802-need-help-with-come-code/
Share on other sites

i believe "  panget yan" thats a wrong practice

 

it better to use something like this

 

switch($_GET['pagez']){

case 'delete':

include 'delete.php'

break;

default:

any page here or put the index page

break;

}

 

in this case you dont have to test it if that page exist

I said the same thing teng said its best to use a switch because even if u don't think it could be any file... any file you could have someone say your container file as the file and then create this infinite loop deal that would crash your server. i.e

www.mydomain.com/index.php?page=index.php?page=index.php?page=index.php?index.php?page=index.php?index.php?page=index.php get the point

like what dude was saying people will know your page so they can run directly on it and besides

its ugly when you see something like

page.php?page=page.html

 

this is better

page.php?page = edit

 

this is clear

switch($_GET['pagez']){

case 'delete':

include 'delete.php'

break;

default:

any page here or put the index page

break;

}

 

but maybe the prob is that your not sure using switch ??

 

 

if u have only a few pages, else if you have like 20 pages your switch/else if will be long.  The idea here is classic needle in haystack logic which is the in_array() function by definition.  Switch by design is for a filtration in which a logical choice needs to be made based on some sort of input such as a percentage base drawing.

I'll give you a bit of an explanation of GET vs POST and you will begin to understand why its ugly.  Get is by design a way of processing variables from Page A to Page B while keeping the variable visitable to the user via the url.  This method has some advantages because the user can then bookmark this page and view it later, or actually edit the url manually.  Secondly it allows the page to be indexed by search engines so that it can be viewed as a unique page.  This is very important because when you are programing you don't want to make a million pages when each on is just different content pulled off a database, instead you create a viewer page and then say view.php?id=1 for example.  It acts like a unique page, but you only store the database entry/single view.php page on your server.  The disadvantage to GET is it shows the data so any type of personal data processing will be visable to anyone who uses that computer and could be stolen.

 

Now to post

Post uses a method of passign data hidden from user (not encrypted technically)  This methods best advantage is that you can hide data like Personal information and password so that they CAN'T be indexed.  Also Post hides the data in a sorta package to be opened on page 2 for you to handle via an array called $_POST.  This is also useful if you haev a lot of data so that the url isn't a big messy string that is porabbly only used once.  The disadvantage to psot is also clear that data can't be indexed for bookmarking/indexing.

 

Overall conclusion:  Use Post always unless you see a clear and defined reason for GET.  In this problem we have a clear use for GET to index all your pages.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.