| | #1 |
| Active Warrior War Room Member |
Hello, I have a URL I'm trying to pull the ID and memberid from. ezcapturepage.com/custom.php?id=17&thememberid=snotb4ll I'm trying to pass the information over to this page. ezcapturepage.com/otopage.php I have the memberid working fine using a session I just cannot get the ID in the URL to also pull in so I can include it in a link on the otopage. Here is the code I have so far. PHP Code: |
| | |
| |
| | #2 |
| HyperActive Warrior War Room Member Join Date: 2010
Posts: 179
Thanks: 17
Thanked 23 Times in 19 Posts
|
If you're trying to get a variable from the URL you need to use $_GET[] to access it.
|
| |
| | #3 |
| Active Warrior Join Date: 2010 Location: Portugal
Posts: 65
Thanks: 6
Thanked 2 Times in 2 Posts
|
You need to change: Code: $thememberid = $_SESSION['thememberid']; $pageid = $_SESSION['pageid']; Code: $thememberid = mysql_real_escape_string($_GET['thememberid']); $pageid = mysql_real_escape_string$_SESSION['id']); |
| |
| | #4 |
| Active Warrior Join Date: 2010
Posts: 74
Thanks: 10
Thanked 11 Times in 11 Posts
|
As RuiGomes said you need to escape your parameters. Just look up SQL injection on wikipedia if you want to learn more (which I strongly advise you to). But for completeness you could end up with: $pageid = " 1';drop table custompages' " SELECT * FROM custompages WHERE id=1';drop table custompages'; Whoops, your table has just been deleted. Of course SQL injection isn't limited to deleting tables. Further to reiterating RuiGomes's point I'd also like to add the importance of keeping the single quotes in the query. The query will execute fine without them but you'll still be open to SQL injection in another form. This is safe: PHP Code: PHP Code: SELECT * FROM custompages WHERE id=1 OR 1=1 Given the use of the query this is somewhat pointless, but if you were trying to verify a users username and password it would allow anything though. Not good. So yeah, whenever grabbing *anything* from a user (GET or POST) always use mysql_real_escape_string() but also remember that this alone is not necessarily enough. |
| |
| | #5 |
| Warrior Member Join Date: 2012 Location: Argentina
Posts: 25
Thanks: 12
Thanked 7 Times in 7 Posts
|
As burton247 says it's pretty important you take into account the point about SQL injection. Another alternative would be to use prepared statements for that. Look at the php docs for it: PHP: Prepared Statements - Manual Hope it helps. Best, Luis |
| |
| | #6 |
| Active Warrior War Room Member Join Date: 2009 Location: United Kingdom
Posts: 40
Thanks: 10
Thanked 20 Times in 1 Post
|
First of all i would use $_POST Its more secure. the way you have it now someone could easily get the contents of your database. Secondly I think you usu PDO (PHP Data Objects) for accessing the database. PDO has bind functionality and prepared statements for extra security. You need to rewrite this code as its is very vulnerable. |
| |
|
| Bookmarks |
| Tags |
| php |
| |