Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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