Solved

How to share variable (imap $mbox) across php pages (newbie question)

Posted on 2006-10-23
4
258 Views
Last Modified: 2012-06-21
I have a frame.
with 2 pages
"toplist.php" (shows a list of email headers )
using
$mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id", "password");

and
"oneemail.php" (to show the body of the selected email from toplist.php)

I wish to only have 1 connection to the mail server ($mbox) and wish to be able to access $mbox from "oneemail.php"
So when a user selects a header in the top list, it will do the retrieval and show it in the bottom "oneemail.php" frame
How can I do this?
0
Comment
Question by:TheRealLoki
[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
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:daohailam
daohailam earned 125 total points
ID: 17793239
You can store all headers in $_SESSION or using shm_put_var/shm_get_var.
0
 
LVL 17

Author Comment

by:TheRealLoki
ID: 17794064
well... the $_SESSION "almost works" for me, but not with the imap_open
here's an example

a.php
====

<?php
 session_start();
 $_SESSION["testvar"] = "this is a test";
 $_SESSION["mailbox"] = imap_open(  "{localhost/pop3:110}INBOX", "testdude@myserver.com", "secret"  );
 // store login details for some reason

 // Check messages
  $check = imap_check($_SESSION["mailbox"]);
  $msgnum = $check->Nmsgs ;
  echo "msgnum = "; echo $msgnum; echo "<br>";
  echo "testvar= "; echo $_SESSION["testvar"]; echo "<br>";
  print_r($_SESSION["mailbox"]);

//  header("Location: b.php");  
// UNCOMMENT THE ABOVE LINE FOR THE 2nd PART OF TEST
?>

running the above php generates

msgnum = 2
testvar= this is a test
Resource id #2

If I add the 2nd file

b.php
====
<?php
 session_start();
 // Check messages
  $check = imap_check($_SESSION["mailbox"]);
  $msgnum = $check->Nmsgs ;
  echo "msgnum = "; echo $msgnum; echo "<br>";
  echo "testvar= "; echo $_SESSION["testvar"]; echo "<br>";
  print_r($_SESSION["mailbox"]);
?>

and uncomment the last line in a.php, I get

msgnum =
testvar= this is a test
0

It looks like the mailbox is not surviving across pages, although other variables are
can anyone help?
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 125 total points
ID: 17794195
As imap_open creates a resource and resources can't be shared between/stored in the session. You will need to reconnect in every page-request to your imap-server
0
 
LVL 17

Author Comment

by:TheRealLoki
ID: 17807756
thanks, split points since both answers were helpful to me
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn how to count occurrences of each item in an array.

627 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