PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 22, 2022

[FIXED] how to fetch part of a string from a given string when position is not fixed in php 5.4.0

 July 22, 2022     php, php-5.4     No comments   

Issue

I have a code which fetches only TANID from the Cookies. Position of TANID is not fixed. This code is working fine on php 7.2 but not on php 5.4

<pre><?php
$myfile = fopen("auth-20180925.log", "r");
$content= fgets($myfile);
$carray=explode('-,-',$content);
$mt = $carray[6];
$data=array_column( array_map(function($v) { return explode('=',trim($v));},explode(';',substr($mt,strpos($mt,'=')+1))),1,0);
$SESSION_COOKIES= ($data['TANID']);
echo $SESSION_COOKIES;
?>

However this code is not running on php 5.4.0 I checked and found array_column is not supported by php 5.4.0. Can someone please suggest how can i achieve this in php 5.4.0

My "auth-20180925.log" looks like this:

2018/09/25 08:32:54-,-dev3.office.abc.eu.com-,-10.00.97.000-,-createAuthenticatedSession-,-00255866-,-"yoya session Created.-,-DST=R4;TANID=31d5865cd24c6c3348gjhdfjghfa79bca
2018/09/17 08:35:09-,-dev3.office.abc.eu.com-,-10.61.88.222-,-logout-,-001586284-,-"yoya session Logout.-,- (TANAUTH=6424f5a9e1b84802abe4b66abc7d8536; MultisecureUserId=00198345; authMarket=be; website=OFFICE; DST=R4; authscheme=SOFTTOKEN; TANID=81110436dfghjdfgj6a402b74; PHPSESSID=fgsfsdf5546545df; market=be)"


Solution

For your case, a simple foreach will suffice:

$data = array_map(function($v) { return explode('=',trim($v));},explode(';',substr($mt,strpos($mt,'=')+1)));
foreach ($data as $datum) {
    if ($datum[0] == 'TANID') {
        $SESSION_COOKIES= $datum[1];
        break;
    }
}
echo $SESSION_COOKIES; 


Answered By - Nick
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing