Php Single Page W/ 'index.php?page=4' Stuff.. - Just read, cuz it's hard to explain..

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #11) by michaelper22 on Feb 5 2006, 07:05 PM. (Line Breaks Removed)
QUOTE(thablkpanda @ Aug 16 2005, 06:42 PM) There are alot of sites out there with the index.php as the main page right? (Namely all of them) However when some coders create sites, they create separate entitites and pages with a ?page=4 modifier, or whatever page they want it to be.I don't know how to do that, because each page is 'based' off of the index.php page, when I find ... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Php Single Page W/ 'index.php?page=4' Stuff.. - Just read, cuz it's hard to explain..

thablkpanda
There are alot of sites out there with the index.php as the main page right? (Namely all of them) However when some coders create sites, they create separate entitites and pages with a ?page=4 modifier, or whatever page they want it to be.

I don't know how to do that, because each page is 'based' off of the index.php page, when I find an example, i'll post it here, but Does anyone know how to do this?


Panda

Like I said, this is hard to explain, so when I get an example, I"ll post it here.

Panda

Reply

palladin
it's easy:

First you must get this variable:

CODE

<?php
 if ( isset($HTTP_GET_VARS['page']))
 {
   $ID = strval($HTTP_GET_VARS['page']);
 }
?>


Next you can use this $ID to chose what page load. In the simple way, using "if, else if"

CODE

<?php
if ($ID == 1)
{
 include("some_page.php");
}
else if ($ID == 2)
{
 include("some_page2.php");
}
else
{
 include("bad_page.php");

}
?>


There is many others way to use this kind variables, from content whole page to content one ceil in table smile.gif


--------------------

Practice is when evrything work but no one know why.
Theory is when work nothing but evry one know why.
Programmers join Practice with Theory - nothing work and no one know why cool.gif

 

 

 


Reply

biscuitrat
Omgz I love you both - Panda for asking the question, and you palladin for answering it. I've been looking for that for ages to paginate my stories so I don't run into page after page of documents.

Reply

truefusion
Here's a way using arrays:

CODE

<?

$page = $_GET['page'];

$i = array(
1 => 'page1.html',
2 => 'page2.html',
3 => 'page3.html'
);

if (isset($page)){
include($i["$page"]);
}

?>


This looks more organized to me. Works the same as palladin's way.

Reply

rvovk
CODE
<?
$val = $_GET['id']; // Replace id with whatever you want to use, eg ?id=page
$val .= ".php"; // Makes the filename complete so if you called ?id=index, it would be index.php it has to look for
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val); // Prevent people from viewing root files like your password (should work i just quikly added it without testing)

if (isset($_GET['id'])) { // Replace id with whatever you want to use, eg ?id=page
if (file_exists($val)) { // This checks if the file you are trying to call exists
include "$val";
}
else {
include "404.php"; // If the file doesnt exists it calls your 404 error page
}
}
else {
include "news.php"; // If ?id= is not set it will now go to your news page
}

// Include this script in your content area
// Run ?id=pagename (without .php) to view a page
?>

Reply

leiaah
CODE
?page=something

So I guess this is what they call a query string?! I've been trying to figure this one out as well.

Palladin:
I'm guessing ID is a variable that you can easily change the value of? Can I use a link for this one e.g. if I want to do ID=2 can I just do this (see code below)?
[CODE]<a href="?ID=2">switch to new page</a>


Reply

palladin
Yea but i make small mistake smile.gif Better write what evry line do for future use.

CODE
<a href="?ID=2">switch to new page</a>

| HTML | this is call index.php?ID=2

CODE
if ( isset($HTTP_GET_VARS['ID']) == TRUE) { CODE }

| PHP | this is check is variable ID are use as argument in page adress

CODE
$ID = intval($HTTP_GET_VARS['ID']);

| PHP | this assign value from HTTP variables (using in adress) to $ID php integer variable for future use. (ID=1)

CODE
$ID = strval($HTTP_GET_VARS['ID']);

| PHP | this assign value from HTTP variables (using in adress) to $ID php string variable for future use. (ID=news)

thats all smile.gif

you can use rvovk example too:

Using check only is variable are called:

http://page.com/index.php?news
CODE
if ( isset($HTTP_GET_VARS['news']) == TRUE) { include("news.php")}


http://page.com/index.php?music
CODE
if ( isset($HTTP_GET_VARS['music']) == TRUE) { include("music.php")}


--------------------

Practice is when evrything work but no one know why.
Theory is when work nothing but evry one know why.
Programmers join Practice with Theory - nothing work and no one know why cool.gif

Notice from cmatcmextra:
Use code tags

Reply

HmmZ
There are many ways to achieve such urls, i personally love them but havent completely figured out the much tougher function based php

I will show you a function i use for News, the authorization that is..:
CODE

Function AuthAddNews() {
Global $user,$uid, $admin, $aid, $db;
if((!isset($admin)) || (!isset($user))){
 Header("Location: index.php");
die();
}
$db->"SELECT * FROM ".$prefix."_permission where userid="".$uid." OR adminid="".$aid."";
$result = query();
$permission = mysql_fetch_rows($result);
if($permission[p_admin]=!1){
if($permission[p_user]=!1){
$permission = false;
$id = "anonymous";
}
} else {
If(isset($admin)){
$id = $aid;
}
if(isset($user)){
$id = $uid;
} else {
die();
}
$permission = true;
}
Header("Location: index.php?act=news&permission=".$permission."&id=".$id."");
}


It's quite simple, first on the frontpage i had a link called News and the link was:
index.php?act=news
you just write it.
this should open the news() function (wich should obviously have been written)

Once in the news function you write your code (for example "view_news","add_news","edit_news") etcetera..

those will each get their link or redirect to their function, easily done by once you want it to get kicked in, you write:
CODE
view_news();

and it will open/include the view_news function, when you do it that way, your url will change:
CODE

index.php?act=view_news


in view_news you can do the same, but, if you have permissions set (guests cant see news for example) you dont have to do it with opening the function within[b] a function, you just redirect it with the necessary (or unnecessary) tools:
CODE
index.php?act=view_news&permission=".$permission."

wich, if its a guest who cant view, will change the url once in the page (and with necessary text to show the visitor it may not see it):
CODE
index.php?act=view_news&permission=false


in the example i used, the permission is checked (wich will be used in the next function) together with the user or admin id (wich will also be needed in the next function), wich gives, for example if its user number 1100:
CODE
index.php?act=news&permission=true&id=1100


in your next function you can write down the code for a false permission and a true permission.

Now, that's not all,
at the end of your page, you need to add the following to get for example the [b]act=news
:
CODE

//first we get the act, wich you can make anything you want!
switch($_REQUEST[act]){
//next we need to set a default, wich could be the "front_page" function
default:
front_page();
break;
//in our example we only make 1 switch..to the news...wich has multiple switches...
//so there are actually several switches, but not all have to be made here, since
//they are within the function, these codes are purely for the thing AFTER act=
//for example...act=news ... the rest behind it is WITHIN the function
case:
news();
break;
}



I hope this made a little sense..
its alot of code and dont want to go through it again >.>

just hoping it helps a bit, we all start from the beginning, im a tiny bit further wich gives me the privilige to be able to help others..right? tongue.gif


Reply

leiaah
QUOTE(palladin @ Aug 17 2005, 05:28 PM)
Yea but i make small mistake smile.gif Better write what evry line do for future use.

<a href="?ID=2">switch to new page</a> | HTML | this is call index.php?ID=2

if ( isset($HTTP_GET_VARS['ID']) == TRUE) { CODE }  | PHP | this is check is variable ID are use as argument in page adress

$ID = intval($HTTP_GET_VARS['ID']); | PHP | this assign value from HTTP variables (using in adress) to $ID php integer variable for future use. (ID=1)

$ID = strval($HTTP_GET_VARS['ID']); | PHP | this assign value from HTTP variables (using in adress) to $ID php string variable for future use. (ID=news)

thats all smile.gif

you can use rvovk example too:

Using check only is variable are called:

http://page.com/index.php?news
if ( isset($HTTP_GET_VARS['news']) == TRUE) { include("news.php")} 

http://page.com/index.php?music
if ( isset($HTTP_GET_VARS['music']) == TRUE) { include("music.php")}
--------------------

Practice is when evrything work but no one know why.
Theory is when work nothing but evry one know why.
Programmers join Practice with Theory - nothing work and no one know why cool.gif
*




Hi..do I have to make the ID variable into a SESSIon or a COOKIE variable in this case? thanks.

Reply

palladin
For cookies:

setcookie(cookieid as string, cookie value, expiration date);
example:

CODE

<?php
setcookie("USER", "GUEST", time()+3600)
?>


expiration date are counting in seconds so call php time() function give you actual time + 3600 seconds (1 hour) after this time cookie was deleted.

setcookie mmust be called before html HEAD section was end;

for get cookie just call

CODE

<?php
 $user = $_COOKIE("USER");
?>


evrywhere you wanna smile.gif

--

Session was little more complex: here a link for php help :]

http://php.net/session


--------------------

Practice is when evrything work but no one know why.
Theory is when work nothing but evry one know why.
Programmers join Practice with Theory - nothing work and no one know why cool.gif

Notice from cmatcmextra:
Use code tags

Reply

Latest Entries

michaelper22
QUOTE(thablkpanda @ Aug 16 2005, 06:42 PM) *

There are alot of sites out there with the index.php as the main page right? (Namely all of them) However when some coders create sites, they create separate entitites and pages with a ?page=4 modifier, or whatever page they want it to be.

I don't know how to do that, because each page is 'based' off of the index.php page, when I find an example, i'll post it here, but Does anyone know how to do this?
Panda

Like I said, this is hard to explain, so when I get an example, I"ll post it here.

Panda

Most of the time, when you see something like that, it means that the page is part of a dynamic site. It's usually run off of some CMS (Mambo, Joomla, or someother one). For example:
CODE
http://roslyn.busstop.trap17.com/mambo/index.php?option=com_content&task=view&id=15&Itemid=26

is what Mambo produces, and this:
CODE
http://busstop.trap17.com/blog/index.php?p=28

is what WordPress puts out. Hope this clarifies things for you.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. page.com/index.php?page= - 359.72 hr back. (2)
Similar Topics

Keywords : php, single, page, w, index, php, page, 4, stuff, read, cuz, hard, explain

  1. Mysql - Max(concat())
    Can anyone explain (0)
  2. Phpnuke Add Download Section
    i want to edit/change stuff around (2)
    In order to add a download onto the website up mine you have to upload it or get it linked from
    another place. There is a form that asks you for Program Name, File Link, Author's Name,
    Author's Email, Filesize: (in bytes), Version, and HomePage. Now im using phpnuke and i want to
    change some parts of the form like Program Name to Artist - Title, or perhaps just take some of the
    stuff out like Authors Name. And where it says "(in bytes)" id like to change it to "(in MB)"
    instead. what do i have to do to edit these? help please i want this to work please reply if ....
  3. Becoming Notice: Undefined Index:
    becoming Notice: Undefined index: (0)
    I am cleaning the erros of a php script with the line error_reporting(E_ALL); in the begginig of it.
    But i am becoming several notices based on the same issue: Notice: Undefined index: add in
    C:\xampp\htdocs\webshop\index.php on line 27 27: if($_POST ) 28: {
    I do not understad why i am becoming this error. Add is a variable sent with the post method by a
    formular. Add is not declared before the POST call in index.php but it should not. If anyone knows
    the answer it would be great so i can clean those notices. Thanks in advanced.....
  4. Designing Index Page With Target
    - the table instead of using frame (13)
    I have been reading up on search engine's ability to cache one's site and I realized that
    FRAME is something these search engines don't really like. You can read it on Google's
    search FAQ and just recently my page was cached by Yahoo after taking down my frame index page to no
    frame page. So here is what I would like to do and I would like you super coders help. PHP seems
    to be the best choice since when using INCLUDE command my index page includes not only my three
    separate pages in one, but it helps to have content rather than showing only HTML FR....
  5. Free Stuff...
    (6)
    just a new and upcoming sites with some free PHP scripts, some web layouts and templates and free
    Photoshop tutorials. the screambox is a specially popular script here. see if u wud like to use some
    of them- click here to access the free stuff. ....

    1. Looking for php, single, page, w, index, php, page, 4, stuff, read, cuz, hard, explain

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, single, page, w, index, php, page, 4, stuff, read, cuz, hard, explain

*MORE FROM TRAP17.COM*
advertisement



Php Single Page W/ 'index.php?page=4' Stuff.. - Just read, cuz it's hard to explain..



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE