Link to home
Start Free TrialLog in
Avatar of hexo dark
hexo dark

asked on

how to get a regex from a cookie

hello

how to get the regex from the cookies ?

exemple cookie

_ga=GA1.2.1143421136.1419395036; 16acd9b63ecbf50de0b8c010c2b7289f=779l2132g7802l2fb7vkpqlh53; _gat=1; YwRuLWF1dGhfNTE4NF8xMjE3NDU=549f9d4038f6c274024048

Open in new window


ty
SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hexo dark
hexo dark

ASKER

hello ty for your help :)

i try and résult work juste one probleme on this part of code i have a (#mi) It is what. ?

function getCookie($data)
{                                   
    preg_match_all('#Set-Cookie: ([^=]*)=([^;]*);?#mi', $data, $match);

    return (empty($match[1]) ? null : implode(';', $match[1]) . '; ');
}

Open in new window

oder cookie
1143421136.1419395036; YWRuLWF1dGhfNTE4NF8xMjE3NDU=54a05ccfc6336342291705; 18acd9b63ecbf50de0b8c010c2b7289f=jn8mg8uroajlsjbobmqg4mmth7; _gat=1; YWRuLWF1dGhfNTUxN17xMjE3NDU=54a05fcd28c4e036210541

Open in new window


i get a cookie  just one part ( 18acd9b63ecbf50de0b7c010c2b7289f; )
But my script manages always not to work nevertheless you have an idea ?
Please add this one line to the top of your PHP script and post the output here, thanks.
var_dump($_COOKIE);

Open in new window

I have nothing to post(show) :) no error
If you have a PHP script that is started by a request that includes a cookie, there will be a value in $_COOKIE.  If you have no value in $_COOKIE, there will still be some output from the PHP function var_dump().  It is never silent.  

You might also want to look into Chrome Developer Tools if you're unsure about the contents of the request variables.  The are really useful when you're trying to write web applications!
https://developer.chrome.com/devtools
You may need to add a die(); command after the var_dump(); command... I think you can even do
die(var_dump($foo));

Open in new window

@Terry Woods  

result
array(0) {
}

Open in new window


-----

@Ray Paseur
Thank you I go and look
Would you please confirm you actually ran:
die(var_dump($_COOKIE));

Open in new window

rather than my example code using $foo ?
yes i use die(var_dump($_COOKIE));
Recommend you use var_dump($_COOKIE) rather than die(var_dump($_COOKIE)).  The former would be expected to print out the value of $_COOKIE.  The latter would be expected to print out the return value from the var_dump() function.  The var_dump() function is documented here:
http://php.net/manual/en/function.var-dump.php

As you can see, it returns "void."  I'm not sure what would appear with that return value!  And it might be caught up in output buffering or something like that.  In Laravel, there is a "dd()" function that runs var_dump() and die() in succession.

If you use var_dump($_COOKIE) and you get output like this...

array(0) { }

... there was no matching cookie returned by the browser.  The browser considered the URL, as well as the protocol (HTTP vs HTTPS) and the sub-domain in deciding whether or not to return the cookie.
var_dump($_COOKIE)
not work for me

i try this

file_put_contents('match'.time().'.txt', print_r($match, true));

Open in new window


résult

Array
(
    [0] => Array
        (
            [0] => Set-Cookie: 18acd9b62ecbf50de0b8c010c2b7289f=ftsdvqalsivpv5hb4kf3ucj1r5;
        )

    [1] => Array
        (
            [0] => 18acd9b63ecbf50de0b7c010c2b7289f=ftsdvqalsivpv6hb5kf3ucj1r5
        )

    [2] => Array
        (
            [0] => ;
        )

)

Open in new window

Thanks Ray; I was going by something I read, rather than something I've used, so I'm sure you're correct.

It's worth mentioning the alternative should generally still have the die immediately after it though, for ease of use, otherwise the output may get lost if the output is complex:
var_dump($_COOKIE);
die();

Open in new window

with
var_dump($_COOKIE);
die();

Open in new window


résult
array(0) {
}

Open in new window

my full code

http://pastebin.com/kFYMY7vL

my script stop on this part
 function getSecurityTokens()
    {
        global $cookie, $videoLink, $videoId;
        $old = $cookie;
    file_put_contents('y'.time().'.txt', print_r($get, true));
        get(SITE_URL . $videoLink);
    file_put_contents('p'.time().'.txt', print_r($cookie, true));
 
        if ($cookie == $old)
        {
            die('Impossible to get  the tokens of the video');

Open in new window


the script stop with error

Impossible to get back the tokens of the video

Open in new window


I think that it is a change in cookies but not sure have you an idea
I'm not sure how to help at this point, so I've just annotated the code snippet with comments.  I think it will help you to follow the logic.

function getSecurityTokens()
{
    // MAKE THESE THREE FUNCTION VARIABLES AVAILABLE IN THE GLOBAL SCOPE, ALSO OUTSIDE OF THIS FUNCTION
    global $cookie, $videoLink, $videoId;
    
    // COPY THE VALUE IN $cookie INTO $old (THE TWO ARE NOW EQUAL)
    $old = $cookie;
    
    // WRITE SOME INFORMATION INTO A FILE -- BUT WHAT?  THE VALUE OF $get IS UNDEFINED IN THIS FUNCTION
    file_put_contents('y'.time().'.txt', print_r($get, true));
    
    // DON'T KNOW WHAT THIS DOES
    get(SITE_URL . $videoLink);
    
    // WRITE THE VALUE OF $cookie (SAME AS THE VALUE OF $old) INTO A FILE
    file_put_contents('p'.time().'.txt', print_r($cookie, true));
 
    // THIS WILL ALWAYS BE TRUE BECAUSE OF THE ASSIGNMENT ON LINE 7
    if ($cookie == $old)
    {
        die('Impossible to get  the tokens of the video');
        
    // THE SCRIPT FAILS BECAUSE OF A PARSE ERROR HERE - THE IF AND FUNCTION STATEMENTS ARE UNTERMINATED

Open in new window

Which information we would need to find the source of the problem

i use this line for test variable

file_put_contents('y'.time().'.txt', print_r($get, true))

Open in new window

I don't know -- I do not understand the application requirements so I'll sign off now.  Good luck and I hope one of our other members can help!

Happy New Year, ~Ray
@Ray Paseur
I do not understand the application requirements
I am going to try to explain at best all this to give you the real context of the script my to ask to a friend to be translated correctly
Back when you posted the code:
function getCookie($data)
{                                   
    preg_match_all('#Set-Cookie: ([^=]*)=([^;]*);?#mi', $data, $match);

    return (empty($match[1]) ? null : implode(';', $match[1]) . '; ');
}

Open in new window

you requested to know the meaning of the #mi

The two # characters are the delimiters for the regex pattern, so the regex pattern is:
Set-Cookie: ([^=]*)=([^;]*);?

Open in new window

And the "mi" characters are pattern modifiers. "m" means multiline so that the wildcard . can match a newline (\n) character (eg so that .* will match multiple lines rather than just up to the next \n character), and "i" means ignore case (eg so that [a-z] would also match A-Z

When you use the getCookie function, do you have the data you need in the $data parameter? If so, is the regular expression working the way you want it to? I can help with updating the pattern if it's not working.
what information is needed for the pattern ? how to obtain this information on the website ?

the full code is here
http://pastebin.com/kFYMY7vL
i got this  cookie.js

http://pastebin.com/S7Sge2Fq

the full code is here  (sorry  The previous code expired)
http://pastebin.com/LFD19Rp6

te cookies
website.fr	FALSE	/	FALSE	18acd9b63ecbf50de0b8c010c2b7289f	j2ata6mfajhoiggfhrjc65je07
website.fr	FALSE	/	FALSE	1420015619	YWRuLWF1dGhfNDU4Ml7w	54a38dd201ca6961978262
website.fr	FALSE	/	FALSE	1420015644	YWRuLWF1dGhfNDU4Ml7xMjE3NDU	54a38dec74248260696300
.website.fr	TRUE	/	FALSE	1483076842	_ga	GA1.2.545715106.1420004811
.website.fr	TRUE	/	FALSE	1420005410	_gat	1

Open in new window

Can you please clarify what value you're wanting to get out of the cookie?
Re hello I found how to use this command line

var_dump($cookie, $old)

Open in new window



résult

string(61) "17acd9b63ecbf50de0b8c010c2b7289f=eh8bnl4pcl6go0f67ituitr6m2; " string(61) "17acd9b63ecbf50de0b8c010c2b7289f=eh8bnl4pcl6go0f67ituitr6m2; "

Open in new window


and $data  is a page html

sorry is not your question just I do not know what to look what to give you I am one begin who tries to understand and to learn I know not which information to give you I'm an inexperienced with php
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Too hard to get the real problem and thus I am going to wait to have more information for re to post

I give you your points for the effort