[SOLVED] Sending variable from one php file to another

This is a discussion on "[SOLVED] Sending variable from one php file to another" within the PHP Forum section. This forum, and the thread "[SOLVED] Sending variable from one php file to another are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 31st, 2007, 08:35
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] 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: Select all
    $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: Select all
<?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; Oct 31st, 2007 at 10:10.
Reply With Quote

  #2 (permalink)  
Old Oct 31st, 2007, 09:20
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Sending variable from one php file to another

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
Reply With Quote
  #3 (permalink)  
Old Oct 31st, 2007, 15:48
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Sending variable from one php file to another

What do you want your sessions to do.
If you are using sessions you must declared this at the top of your code:
PHP: Select all

session_start(); 

and you register a session like so:

PHP: Select all

$_SESSION['sessionname'] = value
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax to include a file as a variable??? WebNinja PHP Forum 7 Feb 5th, 2008 11:00
[SOLVED] sending email once form submitted Emzi PHP Forum 5 Nov 21st, 2007 14:25
How do I add new variable in a .TPL file toasty PHP Forum 1 Oct 9th, 2006 18:27
Is it possible to use an external text file for a variable AdRock JavaScript Forum 2 Sep 15th, 2006 17:25
Sending File without open E-mail Application accessman Databases 0 Sep 26th, 2005 15:51


All times are GMT. The time now is 02:18.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43