Solved

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

Posted on 2006-10-23
4
250 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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