jemz — 2013-04-13T15:42:52-04:00 — #1
Hi can i ask something ,i found it here in sitepoint how to do this in php like url
when every time i click on the link it shows
when i call my page it only gives me like this in url www.mypage.com/gallery.php
there is no
can you help me on this how to achieve like this to have ?do=somvariable
Thank you in advance.
tpunt — 2013-04-13T17:15:40-04:00 — #2
The part you're referring to is called the query string, and is created via the HTTP GET request. In your example above, the do part of the string is a key in the superglobal $_GET array, and the part to the right of the equals sign is the corresponding value.
For example (using your query string above):
echo $_GET['do']; //outputs "variable" (beware of XSS attacks)
One caveat to watch out for when using the HTTP GET request (especially for actions) is CSRF attacks.
jemz — 2013-04-13T23:45:58-04:00 — #3
Hi, Thank you for the reply, can you please elaborate more your example, i am confuse,Thank you in advance.
jemz — 2013-04-14T06:27:42-04:00 — #4
How do i know what page will be loaded in the variable of "do"
avram — 2013-04-14T07:02:01-04:00 — #5
Can you tell us what exactly are you trying to do? You can't know what will be in "do", you generate links with "do" filled out when you generate the page itself. However, note that users can place anything in there, that's why @tpunt wrote "(beware of XSS attacks)". You need to sanitize this variable if you're outputting it to the browser or do include/require based on this.
jemz — 2013-04-14T13:32:20-04:00 — #6
Hi, Okay sorry for my bad english,,...i will try my best to explain you this....when I was navigating in the settings in my control panel i found out that in the left pane there is menu like my setting,my subscription etc...,...under my settings i clicked those links like edit profile,edit avatar,etc..and i found out in the url something like this
I want to know how i can accomplish like that,if i click the link edit profile
the url must be like this
and then it will load the profile form.
just like in the sitepoint,and also it loads the form in the right side.
I hope you got me now.
avram — 2013-04-14T17:34:10-04:00 — #7
Now make files first.php, second.php and third.php with different content inside. You should also make 404.php for "not found" pages. Then in index.php place following code:
//you can place links in this file also
default: //default behavior, if none of above options is located in 'do'
jemz — 2013-04-14T20:34:40-04:00 — #8
Hi thank you for the reply, Oh! so this how to do it...now i know,last thing,why did you test !empty ? instead of isset ?
THank you in advance.
avram — 2013-04-15T03:51:29-04:00 — #9
It's just my way of checking things, you may freely (and probably should) use isset() here. !empty() is not same as isset(), but in certain occasions it has same result. E.g. if someone opens index.php?do= it will be set, but it will also be empty... in other words in such case the isset() check would go through, but !empty() would not.
edit: Actually, when I think about it, isset() is mandatory here. Without it you'll get unwanted notices from PHP.