[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Passing data in $_Session vars

Posted on 2013-11-12
5
Medium Priority
?
255 Views
Last Modified: 2013-11-15
I have a page (BuildingChk.php) that is used by several other pages.  Depending on the page that it came from, it passes data in $_SESSION['Data'].  

The page I'm having trouble with needs to add 2 variables to session variable.  I'm building the session variable like so:

$_SESSION['Data'] = $ROW2['SEQ'].$ROW2['NOR'].$ROW2['SOU'];

This does work.  

My problem is the length of "NOR" and "SOU".  They could be any where from 1 to 4 chars.

Is there a way to set them to 4 chars before building the string?

Also, the following code comes from the page that get's the results.

I've modified the code so that it is only looking for 2 chars in north and south (quick fix).

echo $_SESSION['Data']."<br>";
$strt = substr($_SESSION['Data'],0,9);
$work = $strt."%";
$north = substr($_SESSION['Data'],12,13);
$south = substr($_SESSION['Data'],14,15);
echo $strt."<br>";
echo $work."<br>";
echo $north."<br>";
echo $south."<br>";

The results that I'm getting from the "echo" statements are as follows:
NY10350005755251
NY1035000
NY1035000%
5251
51

Everything is correct except for the $north.  Why is it returning 4 chars instead of 2?

Thanks
Glenn
0
Comment
Question by:breeze351
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39643500
Because the second number is supposed to be the length, not the ending position.
$north = substr($_SESSION['Data'],12,2);
$south = substr($_SESSION['Data'],14,2);

Open in new window

http://us3.php.net/manual/en/function.substr.php
0
 
LVL 12

Expert Comment

by:zappafan2k2
ID: 39643568
Is there any reason you can't simply make $_SESSION['Data'] an array?
$_SESSION['Data'] = array(
    'north' => '...',
    'south' => '...',
    'other' => '...',
    'stuff' => '...
);

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39644830
The PHP session is an array.  It can have as many data elements as you want.  Clogging them up together is a sure way to become confused!

Here is something like what I would recommend.  (I would also avoid the uppercase variable names.)

// NOT THIS: $_SESSION['Data'] = $ROW2['SEQ'].$ROW2['NOR'].$ROW2['SOU'];
$_SESSION['seq'] = $ROW2['SEQ'];
$_SESSION['nor'] = $ROW2['NOR'];
$_SESSION['sou'] = $ROW2['SOU'];

Open in new window

0
 

Author Closing Comment

by:breeze351
ID: 39651969
I stared at the code and could not see it.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39651985
We've all done that!  Welcome to the club :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question