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
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.

 

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.