Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending variable from one php file to another

    Hi this is pretty noob stuff but here goes!

    Ok so I have two php files.
    a.php
    b.php

    a.php deals with some form validation, ending in
    Code:
    	$worked = mail($to, $title, $message, $headers);
    
    	if($worked)	{
    	$confmsg = '<p>Your request for a call back has been sent. A Cruise Specialist will be in touch.</p><p>You will now be redirected back to the page you were previously viewing. If the page 				does not load shortly please <a href="' . $prev . '">click here</a>.</p>';
    	// Insert monitor forwarder here
    	}
    	else	{
    	// It failed
    	$confmsg = '<h1 class="first">Registration Problem</h1><p>There was a problem with your registration, please try again later.</p><p>You will now be redirected back to the page you were previously viewing. If the page does not load shortly please <a href="' . $prev . '">click here</a>.</p>';
    }
    ?>
    <?php session_start();
    $_SESSION['$worked'] = $_POST['$worked'];
    ?>
    Whilst b.php takes the session checks to see if the mail has been sent and if so posts an echo like so:
    Code:
    <?php session_start();
    $callback = $_SESSION['$worked']
    ?> 
    <?php
    if ($callback) {
    // Received new callback submission
    	$callmsg = '<p>We have received a new callback request</p>';
    	}
    else {
    //Did not recive new callback submission
    	$callmsg = '<p>There are no new callback requests</p>';
    	}
    ?>
    <?php echo $callmsg; ?>
    But it doesnt work??? Why is this? What am I not understanding about sessions?

    Thanks in advance. eon201
    Last edited by eon201; 10-31-2007 at 12:10 PM.

  • #2
    New Coder
    Join Date
    Oct 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok ive found out that I should be using sessions for this as it would make my life easier when calling a variable later on in any file. Has anyone get experience with this??

    Thanks. Eon201

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You need to write the session, then go back to your script (redirect),
    or refresh your page (if it's within the same script). Like cookies, there needs
    to be that one extra refresh to send the header.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •