Hello Everybody,

I just join today, and this is my first post.

I know how pass and receive variables thru URL like
www.mysite.com/index.php?var1=ABC&var2=QWERTY

This is OK but what i'd like to know if we can use something like this:
www.mysite.com?username

or www.mysite.com/username but username will change for every user.

And I dont want to make a folder for each user... and put and index.php in each folder.

What I want to do is when the user type www.mysite.com/robert it will see the public profile of robert...

Don't know if you undestand me???
Thanks for your help

what you need to do is use a url like www.mysite.com/profile.php?id=robert

Then at the top of your script you can get that value by using

$id = $_GET[id];

which will give the $id the value of robert

Thank whiteyoh , for your fast answer...

But I akready know this way...
I'm looking for a short way making a URL like www.thesite.con?robert

I'm sure that I already see this kind of URL but I don't know how they "catch"the variable in the index file.

I was thinking about creating a directory(folder) to each user and to put an index file in each folder, but I have a lot of user...
But this way I can give them each a URL like www.thesite.com/robert

Any Idea?
Tx

Thank whiteyoh , for your fast answer...

But I akready know this way...
I'm looking for a short way making a URL like www.thesite.con?robert

I'm sure that I already see this kind of URL but I don't know how they "catch"the variable in the index file.

I was thinking about creating a directory(folder) to each user and to put an index file in each folder, but I have a lot of user...
But this way I can give them each a URL like www.thesite.com/robert

Any Idea?
Tx

Your mind must be playing tricks on you because it's not possible to pass a variable through a URL like that without using a page like index.php or something to pass the variable. What you're trying to do makes no sense at all. In the url site.com/index.php?id=1 the variable id is being passed to the page index.php. You're trying to pass a variable to nothing...

Your mind must be playing tricks on you because it's not possible to pass a variable through a URL like that without using a page like index.php or something to pass the variable. What you're trying to do makes no sense at all. In the url site.com/index.php?id=1 the variable id is being passed to the page index.php. You're trying to pass a variable to nothing...

mm, yes I think I understand you... but if I type

www.thesite.com?robert=1

in the index.php file of thesite.com I have something like

if(isset($_GET['robert'])) $theVar = 'Bonjour Robert'; 
echo $theVar;

And it echo "Bonjour Robert"

but I have to make an long URL www.thesite.com?robert=1

What I'm looking for is to have www.thesite.com?robert...
But think it's impossible...

If you take a look at something called MVC (model view controller) it should give you an example of amending your .htaccess file to change how the URL displays to the user

If you take a look at something called MVC (model view controller) it should give you an example of amending your .htaccess file to change how the URL displays to the user

Thanks for the info... I didn't hear about MVC, but give a "Googling"right now..

And give you feed back ASAP.

Thanks...

Folowing advice of whiteyoh I found this website...

http://www.phpro.org/tutorials/Model-View-Controller-MVC.html

Indeed solution maybe it's here, but seems a little hard to understand.. Now I have to leave the office but tomorrow wil folowing investigations and hope find it...

Rgds...

The Router

The router class is responsible for loading up the correct controller. It does nothing else. The value of the controller comes from the URL. The url will look a like this:
http://www.example.com/index.php?rt=news
or if you have htaccess amd mod_rewrite working like this:
http://www.example.com/news
As you can see, the route is the rt variable with the value of news. To begin the router class a few things need to be set. Now add this code to the router.class.php file in the application directory.

I think I know what you're trying to do now.. your original question wasn't very clear though. You said you were trying to pass a variable.. not rename your url, which is what it seems like your trying to do based on your previous comment ^. Check this out.

http://articles.sitepoint.com/article/guide-url-rewriting

I think the answer to your question is that you want to use an ".htaccess" file to rewrite the url to something much more friendly. There are answers all over for that part.

I am looking at how to generate the page in the first place. I am using Dreamweaver, I got the php script working great on the form, I have linked it to a mysql database and that is working too, I have created a binding for the url to the field name in the database. I just can't figure out how to create the page that will get redirected by the .htaccess file.

Hello to all!

Thank you for you help and time.
Indeed the solution was in .htaccess and mod_rewrite.
Afeter one hour tryin and "googling" I find those intrestings pages:
http://articles.sitepoint.com/articl...-url-rewriting (Provide by codeEgg)
http://www.workingwith.me.uk/articles/scripting/mod_rewrite Clear and simple also provide information about HOTLINKING (intresting)
http://articles.sitepoint.com/article/apache-mod_rewrite-examples Some intresting samples on how to do...

But the final solution I found it in this page (spanish)http://es.how-to.mobi/index.php?id=158328


The solution is use is taken in this page and is

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 
</IfModule>

I have made a test page and you ca try it here. http://bluesquare.asia/lab/modrewrite/

You can go to this page and test with an URL like http://bluesquare.asia/lab/modrewrite/YOUR NAME and you will be redirect to the profile page of YOUR NAME

Thanks to all for your help.
You can tag this thread as SOLVED but if someone need more information... I am here
Have a good day!

Hey PierreJ, well done getting it clear! I got what you wanted from the first thread!

The thing is, your link to the solution is broken, would you have it in any other way?

Thanks a lot
Leo

Hello Leo,

The link isn't broken. Maybe server was down when you try? Maybe you need to insert 'www' after the 'http://'?
Hope it helps.

Hello Leo,

The link isn't broken. Maybe server was down when you try? Maybe you need to insert 'www' after the 'http://'?
Hope it helps.

$_SERVER["QUERY_STRING"] will catch the value 'username' from the url www.mysite.com?username

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.