PDA

View Full Version : PHP parse_str() help needed


nirvana43
10-02-2009, 10:43 AM
Hello
I'm coding a mod for vb

I'm having problem with parse_str() function in following code block :

foreach ($matched as $urls => $names)
{
parse_str($urls);
$temp=$ac;

//*****And then i'm printing values of $temp*********//

}

$urls contains following string data :

/sent?r345dfd32s&link=general&ac=3245534893783&status=waiting

I wanna store only numbers under "ac" in some string variable.

However, above code snippet results no data (blank) in $temp.
Is it because parse_str() is used within foreach() loop?
(I have to use it in foreach() because $urls contains different links everytime. Or is there any other way?)

If i remove foreach() loop then code works perfect.
Can any1 please help me with this??
You will get full credit in mod for solving this issue.

Lynne
10-02-2009, 02:14 PM
You should use the vb cleaner:
$vbulletin->input->clean_array_gpc('r', array(
'ac' => TYPE_UINT,
));

And then you can set it this way:
$temp = $vbulletin->GPC['ac'];

You should go read some of the articles regarding the vbulletin cleaner and making secure mods, like these - https://vborg.vbsupport.ru/showthread.php?t=119372&highlight=cleaner and https://vborg.vbsupport.ru/showthread.php?t=154411

nirvana43
10-02-2009, 04:54 PM
Actually i'm trying to do non vb thing in mod.
So there there is no global.php included.
And i dont think its reasonable to call global.php in script just for this reason.

Also the link i'm trying to parse is not fetched from actual url (the one in browser)
It is just a variable name i used.
So the actual string that has to be parsed is contained in $urls string variable.

How do i get that "ac" numbers?

Lynne
10-02-2009, 05:03 PM
$_GET['ac'] should be the variable name, I believe.

nirvana43
10-03-2009, 01:05 AM
I think you didnt get what i'm trying to do here..
See, this data is not coming from any form etc.
The data is calculated/captured on runtime using preg_match() functions... Its CURL related things i'm doing in mod.
Following code is contained in $urls (Array).
/sent?r345dfd32s&link=general&ac=3245534893783&status=waiting
Everytime, "ac" and "r345dfd32s" things change for each array element.
However, i'm already having $urls (As a string for each index) the only thing is i wanna have "ac" numbers in some variable (For comparison purpose.. i'm not gunna echo 'em).
And yeah, i also tried with urldecode() etc.

The problem is, following code works perfect if i remove foreach() loop (i.e. it will b processing only 1 $urls)
parse_str($urls);
$temp=$ac;


When foreach() loop is added, above code ain't working...
So i guess (it may be stupid but still) parse_str() having hard time because of foreach().
The thing is, i googled a lot (and really a lot)... but i didnt find parse_str() written under foreach() loops anywhere.. but i also didnt find never to use parse_str() under foreach() written anywhere..
So i'm really really confused and stumped!! :(