Jump to content

[SOLVED] preg_match() help


ainoy31

Recommended Posts

Hello-

 

I am trying to use preg_match() on a hidden input value, <input type = "hidden" name = "SESSIONID" value = "0000gecGfGKURryDNn4hgJ1nAFS:-1">  Keep in mind that the value will not be the same everytime. 

 

Here is the code I am having no luck with:

preg_match('/<INPUT TYPE="HIDDEN" NAME="SESSIONID" VALUE="([^"]*?)" \/>/', $data, $matches);

 

If I use print_r($matches), I receive an INVALID result.  Is this possible to do?  Basicly, I am trying to capture a hidden session id using the curl_setopt().  The session id value is auto generated.  Much appreciation.

Link to comment
https://forums.phpfreaks.com/topic/74364-solved-preg_match-help/
Share on other sites

Here is what I have and I still get nothing in return when I echo it.

 

preg_match('/<INPUT TYPE="HIDDEN" NAME="SESSIONID" VALUE="([-A-Za-z0-9:]+)">/', $data, $matches);

 

The value is should something like 0000VzDZZt4xwA11b-6rngxzn6U:-1.  Could it be that I am searching through a big file?  The file has only one SESSIONID word.

 

If you want to match the exact data you posted, you need spaces around =:

 

<?php
preg_match('/<INPUT TYPE = "HIDDEN" NAME = "SESSIONID" VALUE = "([-A-Za-z0-9:]+)">/i', '<input type = "hidden" name = "SESSIONID" value = "0000gecGfGKURryDNn4hgJ1nAFS:-1">', $matches);
print_r($matches);
?>

Thanks for the advice but it is not working.  I am trying to capture the SESSIONID value since it changes everything you go to the webpage.  I am using the curl_setopt() method to accomplish this. 

 

$url = 'http://www.bullocks-express.com/Bullocks/entry';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');

$data = curl_exec($ch);

curl_close($ch);

//(0000VzDZZt4xwA11b-6rngxzn6U:-1) -> example of the sessionid value

 

preg_match('/<INPUT TYPE = "HIDDEN" NAME = "SESSIONID" VALUE = "([-A-Za-z0-9:]+)">/i', $data, $matches);

print_r($matches);

I believe I have narrow the issue down.  The problem is from the website's url.  If I use the http://www.bullocks-express.com/Bullocks/entry?nav=shipTrack or http://www.bullocks-express.com/Bullocks/entry? as my curl url, I do not always get the page where it has a form to fill out.  The form has all the hidden fields and the SESSIONID value is one of them.  That's why when I run this script, it comes up INVALID or an empty array. 

 

I found this out by replacing $data with '<input type = "hidden" name = "SESSIONID" value = "0000gecGfGKURryDNn4hgJ1nAFS:-1"> and running it.  The regular expression returns 0000gecGfGKURryDNn4hgJ1nAFS:-1 as requested.  I am going to contact their IT people.  Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.