Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 29th Apr 2013, 03:27 PM   #1
VIP Warrior
War Room Member
 
Join Date: 1997
Location: Erie, PA
Posts: 9,051
Thanks: 2,899
Thanked 17,186 Times in 4,875 Posts
Blog Entries: 4
Default
PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

So, I'm having what is probably a really basic brain fart here. I have a script that's getting code back from Aweber after someone confirms a subscription. The URL contains subscriber data, in this format, as it appears in the location bar:

Code:
http://example.com/scriptname.php?email=user%40example.com&from=user%40example.com&meta_adtracking=adtrackcode&meta_message=1&name=Freddie&unit=listname&add_url=http%3A%2F%2Fexample.com%2Ffirstscript.php%3Fpage%3D678&add_notes=256.0.0.7&custom%20ref=678

I am attempting to extract that last value (678) from the query string, using this bit of code:

Code:
<?php

error_reporting (E_ALL ^ E_NOTICE);

$default = 1;
$value = $_GET['custom ref'];

if($value != "") {
  $newvalue = $_GET['custom ref'];
} else {
  $newvalue = $default;
}
?>
I've tried it as $_GET['custom ref'] and $_GET['custom%20ref'], and it makes no difference. All it ever returns is the default value of '1'.

What am I screwing up?


Paul

.
Stop by Paul's Pub - my little hangout on Facebook.

Paul Myers is offline  
Unread 29th Apr 2013, 04:17 PM   #2
Warrior Member
War Room Member
 
Join Date: 2013
Posts: 24
Thanks: 0
Thanked 6 Times in 6 Posts
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

Hi!

The var name should be translated to custom_ref, so try: $_GET['custom_ref'].

Also you can output all GET vars to see what is actually in there like this:

var_dump($_GET);
psvent is offline  
The Following User Says Thank You to psvent For This Useful Post:
Unread 29th Apr 2013, 05:29 PM   #3
VIP Warrior
War Room Member
 
Join Date: 1997
Location: Erie, PA
Posts: 9,051
Thanks: 2,899
Thanked 17,186 Times in 4,875 Posts
Blog Entries: 4
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

The query string I get from Aweber is custom%20ref. I'll try it with the underscore, though. Thanks.

Gonna take a while. When you test too many subscriptions from the same IP, it seems Aweber starts slowing them down. A lot. Makes sense from an abuse-prevention perspective, but it's a nuisance for testing your own process changes...


Paul

.
Stop by Paul's Pub - my little hangout on Facebook.

Paul Myers is offline  
Unread 29th Apr 2013, 06:27 PM   #4
HyperActive Warrior
 
Join Date: 2012
Posts: 146
Thanks: 10
Thanked 11 Times in 11 Posts
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

the best thing will be to use var_dump($_GET); to get all the $get values and see what is returned. you can use something like
<pre>
var_dump($_GET);
</pre>
To have a cleaner view of the output

prince55l is offline  
The Following User Says Thank You to prince55l For This Useful Post:
Unread 29th Apr 2013, 06:47 PM   #5
Code Painter
War Room Member
 
saxatwork's Avatar
 
Join Date: 2008
Location: Bangalore, India.
Posts: 124
Thanks: 152
Thanked 31 Times in 27 Posts
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

Originally Posted by prince55l View Post

the best thing will be to use var_dump(Array); to get all the values and see what is returned. you can use something like
<pre>
var_dump(Array);
</pre>
To have a cleaner view of the output
Agree. var_dump($_GET), or print_r($_GET) .

"Be Still Like A Mountain And Flow Like A Great River"
saxatwork is offline  
The Following User Says Thank You to saxatwork For This Useful Post:
Unread 29th Apr 2013, 09:28 PM   #6
VIP Warrior
War Room Member
 
Join Date: 1997
Location: Erie, PA
Posts: 9,051
Thanks: 2,899
Thanked 17,186 Times in 4,875 Posts
Blog Entries: 4
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

The underscore worked. Thank you, psvent.

That one tiny thing was keeping me from getting a new project rolled out. Amazing how something that small can have such an annoyingly large impact.

.
Stop by Paul's Pub - my little hangout on Facebook.

Paul Myers is offline  
Unread 30th Apr 2013, 04:32 AM   #7
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

I wonder why they chose to use a non-standard variable name in the first place? :confused:

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
The Following User Says Thank You to David Beroff For This Useful Post:
Unread 30th Apr 2013, 04:45 AM   #8
Warrior Member
War Room Member
 
Join Date: 2013
Posts: 24
Thanks: 0
Thanked 6 Times in 6 Posts
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

Originally Posted by David Beroff View Post

I wonder why they chose to use a non-standard variable name in the first place? :confused:
Yep, that's weird, but I guess that's a custom var? I've been coding PHP for 10+ years and to be honest I didn't know how PHP (or any other lang for that matter) handles var names like that so var_dump helped out . Btw same thing happens if you replace the space with "+".

Curiously I checked the docs to and I couldn't find a reference of the first bat.

If possible I would suggest to rename the var to prevent any weird things from happening in the future.
psvent is offline  
Unread 30th Apr 2013, 09:10 AM   #9
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

Paul, just an FYI... you should always sanitize all GET or POST data to make sure that it does not contain any malicious code. Of course Aweber would never send malicious code, but a hacker could figure out the URL of your script and then submit bad code to it via GET... and if your code does not filter it out, they could do all kinds of nasty things to your server.

There are several different ways to sanitize GET / POST data (and the best method will depend on what kind of characters your data contains, and what you do with the data after your script receives it).

But if you're positive that the "custom ref" value should contain only numbers, then you can verify that by using 'ctype_digit'...

<?php

$value = $_GET['custom_ref'];

$value = trim($value); // make sure there is no whitespace at the beginning or end of string

if (ctype_digit($value)) {
// The value is a number, so it's safe to run the rest of the script
} else {
// The value is NOT a number, so kill the script
}

?>


Brandon Tanner is offline  
Unread 30th Apr 2013, 09:44 AM   #10
VIP Warrior
War Room Member
 
Join Date: 1997
Location: Erie, PA
Posts: 9,051
Thanks: 2,899
Thanked 17,186 Times in 4,875 Posts
Blog Entries: 4
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

Brandon,

It's all alphanumeric characters. A single string, with no spaces.


Paul

.
Stop by Paul's Pub - my little hangout on Facebook.

Paul Myers is offline  
Unread 30th Apr 2013, 10:37 AM   #11
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: PHP problem: Extracting a value from a query string
Share on: 
fb share twitter share gplus share more share

Originally Posted by Paul Myers View Post

Brandon,

It's all alphanumeric characters. A single string, with no spaces.


Paul
In that case, you can use 'ctype_alnum'...

if (ctype_alnum($value)) {
// The value contains only letters / numbers
} else {
// The value contains something other than letters / numbers
}


Brandon Tanner is offline  
Closed Thread


Bookmarks

Tags
extracting, problem, query, string


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:49 PM.