Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 26th Mar 2014, 01:46 PM   #1
Active Warrior
War Room Member
 
butch04's Avatar
 
Join Date: 2008
Location: PA
Posts: 90
Thanks: 0
Thanked 12 Times in 11 Posts
Blog Entries: 1
Default
In Need Of PHP Help Please
Share on: 
fb share twitter share gplus share more share

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:
<?PHP

session_start
();

$thememberid = $_SESSION['thememberid'];

$pageid = $_SESSION['pageid'];

include 
"config.php";

$getpaypal = mysql_query("SELECT paypal_email FROM members WHERE userid='$thememberid'");

$getpaypalresult = mysql_fetch_array($getpaypal);

$commissionpaypalemail = $getpaypalresult["paypal_email"];

if(
$commissionpaypalemail=="") $commissionpaypalemail="snotb4ll@yahoo.com";

$getpageid = mysql_query("SELECT * FROM custompages WHERE id='$pageid'");

$getpageidresult = mysql_fetch_array($getpageid);

$thepageid = $getpageidresult["id"];


?>

butch04 is offline  
Unread 26th Mar 2014, 02:34 PM   #2
HyperActive Warrior
War Room Member
 
peteJ's Avatar
 
Join Date: 2010
Posts: 179
Thanks: 17
Thanked 23 Times in 19 Posts
Default
Re: In Need Of PHP Help Please
Share on: 
fb share twitter share gplus share more share

If you're trying to get a variable from the URL you need to use $_GET[] to access it.
peteJ is offline  
Unread 27th Mar 2014, 03:51 AM   #3
Active Warrior
 
Join Date: 2010
Location: Portugal
Posts: 65
Thanks: 6
Thanked 2 Times in 2 Posts
Default
Re: In Need Of PHP Help Please
Share on: 
fb share twitter share gplus share more share

You need to change:

Code:
$thememberid = $_SESSION['thememberid'];

$pageid = $_SESSION['pageid'];
to

Code:
$thememberid = mysql_real_escape_string($_GET['thememberid']);

$pageid = mysql_real_escape_string$_SESSION['id']);
Also be aware that since you're using plain old mysql_query, your website will be vulnerable to SQL injection. The mysql_real_escape_string function I added will prevent this, but you should look into prepared statements.
RuiGomes is offline  
Unread 27th Mar 2014, 02:10 PM   #4
Active Warrior
 
Join Date: 2010
Posts: 74
Thanks: 10
Thanked 11 Times in 11 Posts
Default
Re: In Need Of PHP Help Please
Share on: 
fb share twitter share gplus share more share

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:
$pageid = mysql_real_escape_string$_SESSION['id']);
$getpageid = mysql_query("SELECT * FROM custompages WHERE id='$pageid'"); 
This will work but isn't:
PHP Code:
$pageid = mysql_real_escape_string$_SESSION['id']);
$getpageid = mysql_query("SELECT * FROM custompages WHERE id=$pageid"); 
If I inject "1 OR 1 = 1" into your query string then you'll end up with:
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.
burton247 is offline  
Unread 27th Mar 2014, 04:37 PM   #5
Warrior Member
 
lluporini's Avatar
 
Join Date: 2012
Location: Argentina
Posts: 25
Thanks: 12
Thanked 7 Times in 7 Posts
Default
Re: In Need Of PHP Help Please
Share on: 
fb share twitter share gplus share more share

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
lluporini is offline  
Unread 29th Mar 2014, 03:00 PM   #6
Active Warrior
War Room Member
 
Join Date: 2009
Location: United Kingdom
Posts: 40
Thanks: 10
Thanked 20 Times in 1 Post
Default
Re: In Need Of PHP Help Please
Share on: 
fb share twitter share gplus share more share

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.
jamesc1985 is offline  
Closed Thread


Bookmarks

Tags
php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:59 PM.