Page 1 of 2

[SOLVED] newbie question

Posted: Fri Feb 25, 2005 8:15 pm
by rafi
Hello again .
I have a small quick question please.
when there's websites with like index.php=contact..
and it goes to the contact page..
how it called when you do something like that ?
just the name..I wanna learn how to do that..
Thanks alot..

Posted: Fri Feb 25, 2005 8:55 pm
by feyd
you mean like index.php?contact or index.php?page=contact

they usually involve looking at $_GET or $_SERVER['QUERY_STRING'] .. I don't know of a definitive name..

Posted: Fri Feb 25, 2005 8:57 pm
by smpdawg
If you are using Apache, you can use url rewriting to translate a URL from a more readable form to something that works with PHP.

If you want to have a URL like this:

http://www.somesite.com/test.php?contact

You just need to look at $_SERVER['QUERY_STRING'] and you will see what is after the question mark.

edit - Too fast feyd, you beat me to it.

Posted: Fri Feb 25, 2005 9:53 pm
by rafi
Yes exactly..
This is really hard to do..

Posted: Fri Feb 25, 2005 10:08 pm
by feyd
if you're asking if it's hard.. no.. it's probably the most used area of php, as the url is a logical way to transfer in request information.

Posted: Fri Feb 25, 2005 10:14 pm
by rafi
yeah..
I know its common in PHP..
I've made this..
http://oktober.co.il/rafi/test/new/contact.php
using
<form method="post" action="mail.php?act=contact">
and then it goes to mail.php?act=contact
but i'd like to do that without POSTING anything..
I've find this Tutorial
http://www.freewebmasterhelp.com/tutorials/php/6
its looks like exactly what I want to do..but I make out anthing..
$variablename=$_POST['variable'];
$variablename=$_GET['variable'];

Posted: Fri Feb 25, 2005 10:23 pm
by feyd
I don't quite understand what you are asking... you want to link to mail.php with the url variables that'd be used via that form?

mail.php?act=contact&username=Steve&email=steve@foo.com

Posted: Fri Feb 25, 2005 10:43 pm
by rafi
I wanna create a single page..index.php
that from there..people would be able to visit other sections of the site..f.x
index.php=profilio
without going to profilio.php..
I want the entire site to go through index.php..
if you'll please help me doing one page..I don't think i'll be hard doing the rest..
:D

Posted: Fri Feb 25, 2005 11:04 pm
by feyd
create a list of known, safe files you'll allow referencing to.. and match the input to it, then include the file.

Code: Select all

$knownFiles = array('contact'=>'contact.php', 'portfolio'=>'portfolio.php', 'default'=>'default.php');
$inc = (isset($_SERVER&#1111;'QUERY_STRING']) && !empty(trim($_SERVER&#1111;'QUERY_STRING'])) ? trim($_SERVER&#1111;'QUERY_STRING']) : '');

if(!isset($knownFiles&#1111;$inc])) $inc = 'default';

include($knownFiles&#1111;$inc]);

Posted: Fri Feb 25, 2005 11:21 pm
by rafi
is this script supposed to be inside the index.php/default.php
so it should be
<?php
then the code
and end with ?>
I get the whole $knownFiles = array('contact'=>'contact.php', 'portfolio'=>'portfolio.php', 'default'=>'default.php'); thing..I just don't get where to put it..
Thank alot..
& sorry for the newb question :lol:

Posted: Fri Feb 25, 2005 11:24 pm
by feyd
yes. it needs to be inside php code tags..

Posted: Fri Feb 25, 2005 11:41 pm
by rafi
i'm getting this error:

Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in F:\Webspace\disk20\oktober.co.il\oktober.co.il\www\rafi\test\new\test.php on line 5

here's the phpinfo incase you need it..
http://www.oktober.co.il/rafi/test/info.php

Code: Select all

<?php 


$knownFiles = array('contact'=>'contact.php', 'portfolio'=>'portfolio.php', 'default'=>'default.php'); 
$inc = (isset($_SERVER&#1111;'QUERY_STRING']) && !empty(trim($_SERVER&#1111;'QUERY_STRING'])) ? trim($_SERVER&#1111;'QUERY_STRING']) : ''); 

if(!isset($knownFiles&#1111;$inc])) $inc = 'default'; 

include($knownFiles&#1111;$inc]);

?>
and that's the code inside the tags..I've prodably messed something up :(
once it works it should be test.php=contact ..right..
http://oktober.co.il/rafi/test/new/test.php

Posted: Fri Feb 25, 2005 11:58 pm
by feyd
as always.. the code was untested...:roll:

Code: Select all

<?php


$knownFiles = array('contact'=>'contact.php', 'portfolio'=>'portfolio.php', 'default'=>'default.php');
$inc = (!empty($_SERVER&#1111;'QUERY_STRING']) ? trim($_SERVER&#1111;'QUERY_STRING']) : '');

if(!isset($knownFiles&#1111;$inc])) $inc = 'default';

include($knownFiles&#1111;$inc]);

?>
works..

Posted: Sat Feb 26, 2005 12:06 am
by rafi
Yeah..I get no errors now..
But is it supposed to work with test.php=contact ?
there's a file called contact.php and it won't load it..
Did I use the wrong cmd or something?

Posted: Sat Feb 26, 2005 12:11 am
by feyd
foo.com/path/test.php?contact