Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-10-23
4
Medium Priority
?
266 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 500 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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

773 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