| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Get the FULL url in php [including "id=1" part..] Hey Is it possible to get the FULL url that the user is on? I made this login script..and redirects u back to the page u were on before..but it doesnt get the last part of the urll..for example if the user is on this page when they login: http://localhost/index.php?action=viewmedia&id=1 after using : $_SERVER['PHP_SELF'] they are redirected to index.php how do i make it so it gets the Last part 2 Thanks
__________________ |
| |
| | #2 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |
| | #3 (permalink) |
| NamePros Regular Join Date: May 2005 Location: England
Posts: 392
![]() ![]() ![]() | Out of interest, why is it better to do it that way rather than just using $_SERVER['REQUEST_URI']?
__________________ -Beaver6813.com - Web Developer Extraordinaire! |
| |
| | #5 (permalink) | ||||
| A Wealth of Knowledge Join Date: Aug 2004
Posts: 3,809
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Either clean it or use the switch() function -Steve | ||||
| |
| | #6 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | Not safe at all...especially if the $_GET[] array is evaluated Code: http://www.yourscript.com/?%24_SERVER%5B'QUERY_STRING'%5D+%3D+'%2Frestricted%2Fpath'%3B
__________________ Web Development |
| |
| | #8 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | What I posted above doesn't even need to be used in a mysql query to be effective. Any statement that runs the 'eval();' command with $_SERVER['QUERY_STRING'] mentioned anywhere therein will fall victim to this.
__________________ Web Development |
| |
| | #9 (permalink) | ||||
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| ||||
| |
| | #10 (permalink) | ||||
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
That is far beside the point anyway, Personally, topic solved? Yes? | ||||
| |
| | THREAD STARTER #11 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | hm i cleaned it up using htmlspecialchars() is it safe enough? the only reason i m using this is because i have a login form on the right panel..so when some1 logs in..on any page..i want them to be redirected to the same page..and if they are in a page that has "id=1" or w.e...it doesnt redirect them to that ..if i just use $_SERVER['PHP_SELF'] i m using the way dan told me about..is that okay or should i switch to what beaver mentioned?
__________________ |
| |
| | #13 (permalink) | ||||
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Both Dan and Beaver's suggestions are exact, only Dan was using the two pre defined variables for page name and query string where as Beaver's in pre-combined to give both. | ||||
| |
| | #14 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | I would personally do this: Code: header("Location: http://www.yoursite.com/yourscript.php?id=".htmlspecialchars(escape($_GET[id])));
__________________ Web Development |
| |
| | #15 (permalink) | ||||
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() Also why use htmlspecialchars here, and escape is not a function... | ||||
| |
| | #16 (permalink) |
| Senior Member Join Date: Oct 2006 Location: NJ
Posts: 1,152
![]() ![]() ![]() | Ah...I wrote the escape function for use in one of my programs...that's why its there In this EXAMPLE I would do that ![]() I havent done this in a while...maybe substitute htmlspecialchars for addslashes.
__________________ Web Development |
| |
| | #18 (permalink) |
| NamePros Regular Join Date: May 2005 Location: England
Posts: 392
![]() ![]() ![]() | There are functions specially designed in PHP, if you're using MySQL, i use a couple on my scripts like: PHP Code: P.S (If you find anything wrong with the snippet of code above, lemme know so i can fix in my latest script
__________________ -Beaver6813.com - Web Developer Extraordinaire! |
| |