Jump to content
xisto Community
thablkpanda

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

Recommended Posts

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?PandaLike I said, this is hard to explain, so when I get an example, I"ll post it here.Panda

Share this post


Link to post
Share on other sites

it's easy:

First you must get this variable:

<?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"

<?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 :)


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

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 :D

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Here's a way using arrays:

<?$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.

Share this post


Link to post
Share on other sites
<?$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=pageif (file_exists($val)) { // This checks if the file you are trying to call existsinclude "$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?>

Share this post


Link to post
Share on other sites

?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)?

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

Share this post


Link to post
Share on other sites

Yea but i make small mistake :) 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 :D

 

you can use rvovk example too:

 

Using check only is variable are called:

 

http://forums.xisto.com/no_longer_exists/

if ( isset($HTTP_GET_VARS['news']) == TRUE) { include("news.php")}

http://forums.xisto.com/no_longer_exists/

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 :D

 

Notice from cmatcmextra:
Use code tags

Edited by cmatcmextra (see edit history)

Share this post


Link to post
Share on other sites

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..:

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:

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

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 a function, you just redirect it with the necessary (or unnecessary) tools:

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):

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:

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 act=news

:

//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? :)

Share this post


Link to post
Share on other sites

Yea but i make small mistake :) 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 :D

 

you can use rvovk example too:

 

Using check only is variable are called:

 

http://forums.xisto.com/no_longer_exists/

if ( isset($HTTP_GET_VARS['news']) == TRUE) { include("news.php")} 

 

http://forums.xisto.com/no_longer_exists/

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 :D

175494[/snapback]


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

Share this post


Link to post
Share on other sites

For cookies:

 

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

example:

 

<?phpsetcookie("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

 

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

evrywhere you wanna :)

 

--

 

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

 

http://de2.php.net/manual/de/features.sessions.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 :D

 

Notice from cmatcmextra:
Use code tags

Edited by cmatcmextra (see edit history)

Share this post


Link to post
Share on other sites

Well that's nice, I've got like twenty ways to do the same thing. Thanks people. I knew it was a if-then relation, and else was involved, but I could never get it to work right, the problem I had was in my 'get' function I think. But that's irrelevant. Thanks alot homies.Mr. Panda

Share this post


Link to post
Share on other sites

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:
http://roslyn.busstop.trap17.com/mambo/index.php?option=com_content&task=view&id=15&Itemid=26
is what Mambo produces, and this:
http://busstop.trap17.com/blog/index.php?p=28
is what WordPress puts out. Hope this clarifies things for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.