1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Loopy Array

Discussion in 'PHP' started by nfzgrld, Apr 27, 2005.

  1. #1
    In the spider app for Axelis I have a routine that is supposed to check for possible session ID strings and kill them off. It works for the most part, but there is a situation that I've just become aware of that is very strange.

    It works like this. I use parse_url() to take the url appart. Then I take the query string from the resulting array and explode it on "&". This gives me an array with all of the individual parts of the string. If the element is 16 bytes or greater I leave it out when I put the string back together. This works fine except for one thing. If the session ID string is the first part of the query, if it comes right after the "?", it doesn't work! I can't for the life of me figure this out.

    I use a for loop to look at the array(). I start looking at element 0 so it shouldn't be a problem. Here's the code for the loop:

    
    if(strlen($bqury) > 0){
    	$ckqr = explode("&", $bqury);
    	$nq = "";
    	for($a=0;$a<count($ckqr);$a++){
    		if(strlen($ckqr[$a]) < 16){
    			$nq .= $ckqr[$a] . "&";
    		}
    	}
    	if(strlen($bqury) > 0){$bqury = "?" . substr($nq, 0, strlen($nq)-1);}
    }
    
    Code (markup):
     
    nfzgrld, Apr 27, 2005 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    After you explode it, parse the first element again and get the varaible after the ? mark maybe?
     
    noppid, Apr 27, 2005 IP
  3. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #3
    Without seeing what's in $bqury (or how you get it exactly), it's hard to know for sure... but this should work I think:

    if ($bqury) {
    	$ckqr = explode ('&', $bqury);
    	foreach ($ckqr as $key => $val) {
    		if (strlen ($val) >= 16) unset ($ckqr[$key]);
    	}
    	$bqury = implode ('&', $ckqr);
    }
    PHP:
    Although, you would be better off using the actually session variable name to find it, rather than anything > 15 characters IMO.
     
    digitalpoint, Apr 27, 2005 IP
  4. nfzgrld

    nfzgrld Peon

    Messages:
    524
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The $bqury var is nothing more than the query portion of the results from the parse_url function. That result is basically everything after the "?" in the query string.

    Shawn, your code is a bit more elegant than mine, but I wonder if it would solve the problem with the first element not being affected even if it meets the conditions. I'll probably change it to something like what you've done there, but if that doesn't fix the problem, then what?I can't figure out why it wouldn't work to begin with.

    You're right about using the query string ID, but remember that this is a spider. I haven't yet figured out, if it is even possible, how to have PHP identify if there is a session ID there, and if so, what is it called. If I could figure that out it would solve a lot of problems obviously. Of course, it seems to me if that were possible all the hoops we jump through to turn off session IDs for spider bots wouldn't be necessary.
     
    nfzgrld, Apr 27, 2005 IP