[SOLVED] newbie question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

[SOLVED] newbie question

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post 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.
rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

Post by rafi »

Yes exactly..
This is really hard to do..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

Post 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'];
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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]);
rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes. it needs to be inside php code tags..
rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
rafi
Forum Newbie
Posts: 19
Joined: Wed Nov 24, 2004 9:36 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

foo.com/path/test.php?contact
Post Reply