Log in

View Full Version : changing url php page ...



insanemonkey
09-24-2007, 09:07 PM
OK, here I go.

My urls on my pages are, index.php, about.php, contact.php, graphics.php.

I want to know how do i do(i think php includes get????) it so I can have the url looking like this when I goto a page on my site...

http://www.mydomain.com/index.php
http://www.mydomain.com/index.php?page=about
http://www.mydomain.com/index.php?page=contact
http://www.mydomain.com/index.php?page=graphics

Please list a little script if possible..

thetestingsite
09-24-2007, 09:19 PM
Something along the lines of this:



<?php

$pages = Array(
'about' => 'about.php',
'contact' => 'contact.php',
'graphics' => 'graphics.php'
);

if (isset($_GET['page']) && array_key_exists($_GET['page'],$pages)) {
include($pages[$_GET['page']]);
}
else {
include('defaultpage.php');
}
?>


Simply edit the items highlighted above to point to your files. Also, edit where it says defaultpage.php to whatever you want your default page to be; such as main.php or whatever.
Hope this helps.

insanemonkey
09-24-2007, 09:22 PM
ty i will test this out...

insanemonkey
09-24-2007, 09:37 PM
is there a way instead of include but got the page..

say i want to goto about page and i click the about button, I would like it to send me to that page with index.php?page=about instead of including the page..

thetestingsite
09-24-2007, 09:43 PM
Do you mean masking the url? So that instead of this: about.php it is like so: index.php?page=about?

If so, you may need to look into htaccess for this. Other than that, the best way would be to do includes.
Hope this helps.

insanemonkey
09-24-2007, 09:51 PM
NEVERMIND, I LUV YOU!!! lol,jk but Thankyou oh so much!!!!!!!!

insanemonkey
09-24-2007, 09:56 PM
oh another thing, sorry lol.. how would I go about do this.....

say I wanted to goto this page

index.php?page=graphics

then I click on another link. to graphics>> cursors

index.php?page=graphics?=cursors

is there a possible way to do this?



nevermind figured it out!!!!!

thetestingsite
09-24-2007, 10:02 PM
In whatever page you have; let's say graphics.php, you need to call the variables like so:



<?php
echo $_GET['var'];
?>


Then you can call the page like so:



<a href="index.php?page=graphics&amp;var=whatever">Text</a>


That will produce on the page (when called):



whatever


Hope this helps.

(NOTE: this was only an expample, the possibilities are endless when you get going on it.)

insanemonkey
09-24-2007, 10:21 PM
Actually what I did was just add another thing under page arrays
and it looks like this

'contact?=submitform' => 'urlblahblah.php',

and it works kool, thanks guys!!