Forum Moderators: coopster

Message Too Old, No Replies

New to PHP Content to match URL

         

flanok

11:02 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



Hi,
I am new to PHP (Very New).
I had one lesson from someone who does know his stuff and I thought I understood, but now I realise I don't.

I have a site where the database is not connected to PHP.

I would like to know a command where the URL typed matches what is then displayed on the page.

Ie url is www.mysite.co.uk/great-stuff
or url is www.mysite.co.uk/not-so-good
I would then like this to be show on the page (where I choose)
For example
my subject is great stuff as usual.
or my subject is not so good as usual.

Can I do this without a database. (something else I would have to learn)
Or can it be done without.
Thanks
Mark

eelixduppy

11:28 pm on Oct 11, 2006 (gmt 0)



You can do something like this. This is a basic example, mind you; you may want to expand on it:

page.php


<?php
if([url=http://us3.php.net/manual/en/function.isset.php]isset[/url]($_GET['subject'])) {
echo 'My subject is '.$_GET['subject'].' as usual!';
}
?>

Now type this into the url for this page:


http://your_site.com/page.php?subject=stuff

This example uses the $_GET Superglobal [us3.php.net].

Also, for more PHP learning sources visit this thread on Learning PHP - Books, Tutorials and Online Resources [webmasterworld.com] from our Library [webmasterworld.com].

Good luck!

Little_G

11:33 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



... and if you want the url to look like you mentioned then you'll need to use mod_rewrite [webmasterworld.com]

Somthing like:

RewriteEngine on
RewriteRule ^/subject/(.*)$ /page.php?subject=%1 [L]

Andrew

flanok

11:46 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



Thanks it works!

Can I also enter this code in between other html text?
And can I enter this within my meta tags.

Thanks again

Mark

eelixduppy

12:42 am on Oct 12, 2006 (gmt 0)



Yes you can do all that if you want. Refer to String Operators [us3.php.net] for more information regarding string concatenation.

flanok

1:29 am on Oct 12, 2006 (gmt 0)

10+ Year Member



That is brilliant
One last thing.
I can't get the rewrite to work.

Is there another way to write this?
I already have a rewrite in place taking non www to www and index.htm to /.

Thanks Again Mark

Psychopsia

2:14 am on Oct 12, 2006 (gmt 0)

10+ Year Member



Hi!

You should use $ instead of % in the RewriteRule:

Like this:

RewriteEngine on
RewriteRule ^subject/(.*)$ /page.php?subject=$1 [L]

If you want to keep the url in the address bar replace the L with: nc

More information here: [webmasterworld.com...]

[edited by: Psychopsia at 2:16 am (utc) on Oct. 12, 2006]

flanok

10:26 am on Oct 12, 2006 (gmt 0)

10+ Year Member



Thanks
Great stuff learned a lot
Mark