Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now