Is there anyway to turn index.php?page=home to just index.php?home, so I can still use $_GET? or is this impossible? I would have googled this but I couldn't find anything anywhere.
UPDATE let me be more clear, i need to get the string AFTER index.php? so i can use it in my php code
Asked
Active
Viewed 74 times
-1

Mcclures
- 1
- 5
-
I think you can use `index.php?home`, check using `isset($_GET['home'])`, but the downside is `home` does no have any value, or at least that's what I know – Carl Binalla Jun 28 '17 at 05:58
-
i need to be able to get the string "home" or whatever string is after index.php? – Mcclures Jun 28 '17 at 06:00
-
Does `isset($_GET['home']) ? 'Home' : '';` suffice? – Carl Binalla Jun 28 '17 at 06:02
-
If the server is run by Apache this is usually done with .htaccess and mod_rewrite – that should give some keywords to google with. Although it's more common to shorten it directly to example.com/home instead of example.com/index.php?home. – JJJ Jun 28 '17 at 06:04
-
@Swellar it needs to be dynamic, as in index.php?home can be anything like index.php?string, index.php?r94fr904jughg etc. – Mcclures Jun 28 '17 at 06:10
-
You mean without redirect? – odedta Jun 28 '17 at 06:11
-
@JJJ mod_rewrite still wont help, i need the string after index.php? – Mcclures Jun 28 '17 at 06:11
-
If you only need a string after a certain character use `substr()`. I think you are not explaining What you need to achieve and what the problem is in the first place very well. – odedta Jun 28 '17 at 06:12
-
@odedta yes, im making a chat where anyone can make a chat with any string – Mcclures Jun 28 '17 at 06:13
-
Use this then: https://stackoverflow.com/a/176341/4711865 - or just substr to get a part of a string – odedta Jun 28 '17 at 06:14
-
Uh, that's exactly what mod_rewrite does. It rewrites index.php?xxx to index.php?page=xxx. – JJJ Jun 28 '17 at 06:15
-
@JJJ thats NOT what i want, i want the string to turn into a VARIABLE i can use – Mcclures Jun 28 '17 at 06:18
-
@odedta thanks, this works. i would accept your answer but its a comment – Mcclures Jun 28 '17 at 06:18
-
1Jesus christ. What exactly do you then think that mod_rewrite does? When the user types example.com/index.php?home into the browser, mod_rewrite turns the URL *internally* (i.e. invisible to the user) into example.com/index.php?page=home. That way you get the variable from `$_GET['page']`. – JJJ Jun 28 '17 at 06:20
-
@JJJ, I think he means that he wants to use any string inside a chat app, not necessarily the address bar. Does mod_rewrite change any string typed by the user anywhere and sent to server or only in the address bar? – odedta Jun 28 '17 at 06:24
-
@odedta I don't know what you mean by "typed by the user anywhere" – if you mean Ajax calls, then yes, the server doesn't know/care how the request was made. – JJJ Jun 28 '17 at 06:27
-
@JJJ For example, yes. I see, thanks. :) – odedta Jun 28 '17 at 06:28
1 Answers
0
If you want to use the URL and string the hostname out you can use Robert Elwell answer
$foo = "http://www.example.com/foo/bar?hat=bowler&accessory=cane";
$blah = parse_url($foo);
print_r($blah);
Array
(
[scheme] => http
[host] => www.example.com
[path] => /foo/bar
[query] => hat=bowler&accessory=cane
)
If you want to use any string you could use [substr][2]
to return only a part of a string.
If you have a more concrete example I could give an example on how to solve it.

odedta
- 2,430
- 4
- 24
- 51