/    Sign up×
Community /Pin to ProfileBookmark

I need some help, i cant figure out what this is called so i can’t search for it. Let me explain what I’m trying to do.

Lets say I own mydomain.com I want to turn whatever is placed after the .com/ into a variable for example if you type: [url]http://www.mydomain.com/iscool[/url] the variable $rating would equal iscool or something simalar, I have no idea what its called but if anyone could tell me how I would achieve this it would be great.

Thanks,
Metro

to post a comment
PHP

19 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJun 22.2004 — everything that follows the "?" is called a search, and everything that follows the "#" is called a hash

in php, you can access the search as a associative array, ex.[code=php]<?php
// http://www.domain.com/index.php?a=1&b=2
// use the $_GET to access the search of a url

echo $_GET['a']; // would print '1'
echo $_GET['b']; // would print '2'
?>[/code]
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — I know that but i want to rid of the ?a= part and just have 1 and it automatically does it, i will only be having one URL set variable.
Copy linkTweet thisAlerts:
@MstrBobJun 22.2004 — I'm a bit confused. You will have to have a index.php file in the "iscool" directory you have made anyway. Would it not be simpler to have a 'coolthings.php' file, and then your links can send the variables as ShrineDesigns showed you? What's wrong with it? If your trying to get the directory, I guess you could do something like:

[code=php]
<?PHP
$dir = getcwd();
$len = strlen($dir);
$pos = strrpos($dir, "/");
$ss_len = ($len - $pos);
$sub_str = substr($dir, $pos, $ss_len);
$sub_str = str_replace("/", "", $sub_str);
$rating = $sub_str;
?>
[/code]


But if you have to make the directories and the directory names cannot change, then why not simple code it in as

[code=php]$rating = "iscool";[/code]

?
Copy linkTweet thisAlerts:
@ShrineDesignsJun 22.2004 — can't, it would have to atleast be http://www.domain.com/index.php[b]?iscool[/b] cause, http://www.domain.com/[b]iscool[/b] the browser would think this is a directory not a url search parameter
Copy linkTweet thisAlerts:
@shimonJun 22.2004 — ahh... I see

What you're looking for here is a rewrite rule .....errr *scratches head*


*thinks a bit*



-------
RewriteEngine on

RewriteRule ^/(.*)$ /index.php?var=$1 [L]
--------




the idea being that the public URL is yourdomain.com/iscool but internally the request would function like mydomain.com/?var=iscool and you can happily use your $_GET vars like normal

Which is kinda what you're looking for ?

You would need to either configure that rule into your httpd.conf or in a .htaccess
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — heres an example whois.sc does it great.

check it out

http://www.whois.sc/yourdomain.com

you can replace yourdomain with any domain you want to look up, im basicly going to be using it like that but not looking up domains.
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — Excuse my double post but I have found an htacess file that gives me something very close.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [L]

RewriteRule ^([^/]+)/$ ./index.php?var=$1 [L][/QUOTE]


It works except you have to do.

yourdomain.com/iscool/

it wont work with

yourdomain.com/iscool

I don't know why maybe someone can help?
Copy linkTweet thisAlerts:
@solavarJun 22.2004 — What you are looking for is the function

[B]parse_url[/B]
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — that doesnt exactly help me, I looked it up and it doesnt seem to do what im looking for unless im looking wrong..?
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — *bump* ?
Copy linkTweet thisAlerts:
@solavarJun 22.2004 — *bump* ?
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — I was trying to get more people to notice the thread, hoping to get some more help...?
Copy linkTweet thisAlerts:
@solavarJun 22.2004 — Right, how far have you got now?

My impression was that you were trying to break up a given url and extract bits and pieces of it.

I'm not so sure now.
Copy linkTweet thisAlerts:
@metrosoccer12authorJun 22.2004 — Okay okay, I'll do a quick re-explain u pretty much got it right.

I want to set a variable in index.php.

The variable will be whatever is typed after the slash in my domain.

Like

yourdomain.com/this part right here sets the variable

I don't know how to do it.

I don't want ?variable=whatever I just want the variable.
Copy linkTweet thisAlerts:
@MstrBobJun 22.2004 — This still seems pointless to me :rolleyes: If your doing this thing with the slash and reconfiguring apache, will you even be able to have any directories, or will your index.php try and read them all as variables?
Copy linkTweet thisAlerts:
@shimonJun 23.2004 — you're absolutely right Mr Bob - that would be the drawback with such a broad rewrite rule, all your images, css, javascript would get rewritten and everything would be a bit of a mess, quite frankly

that could be fixed by tinkering with the regular expression though. We would probably want to eliminate certain suffixes and certain directories. It would be kinda complex and I'm personally not brave enough to give it a shot right now (got work to do too ?) but it's possible, definitely.
Copy linkTweet thisAlerts:
@BonnerJun 24.2004 — I removed both my previous posts after reading through what everyone else put and then realised that there was a mention of folders being inaccessible.

The script I written can access folders in certain conditions and I never used apache to handle the URL's as it is all done in 1 script.

I take it you are looking for something like this:

http://dancedevils.newstop.co.uk/en/
Copy linkTweet thisAlerts:
@shimonJun 24.2004 — I think the whole issue of folders is possibly a red herring here - my understanding was that the guy wanted to be able to add an arbitrary string after the first slash after his domain name and read it into a variable.

(And I dont think he wants to create an infinite number of folders to handle all those requests...)

So several people said it couldn't be done

2 or 3 of us metioned that with (careful) use of mod_rewrite it could be done quite nicely

But if you've got a way of doing it without mod_rewrite and without a whole bunch of folders, well I'd sure like to see that, and probably use it ?
Copy linkTweet thisAlerts:
@BonnerJun 24.2004 — It has a few bugs that need ironing out, I would rather not yet share it with everyone since there are still a few security issues too.

If you send me an e-mail to [email][email protected][/email] I will send it back to you in an attachment. The script needs tidying up too, bits 'n' bobs are just stick in since there was no plan on what I creating when I first started.
×

Success!

Help @metrosoccer12 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...