quick php question..

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
hey guys,

I want to pass a varaible from one page to another using the post method but without using a form as no data needs to be inputted from the user.

Any ideas??

thanks in advance
 
I'd still use a form but use the forms hidden fields. Then control the form submit using javascript.

Using a form doesn't mean it has to be used for user data entry. I've used a few hidden forms on the same page for controlling hidden data. The user doesn't even know its there. Sometimes it just makes life easy.
 
i'm very new to php.

how do i go about using a session then??

I've read php.net but I'm still not clear how i would imperment it on to my site.

cheers
 
Call session_start at the top of each page, and you can then use the $_SESSION superglobal as a persistent variable across pages:

PHP:
// Page 1

session_start();
$_SESSION['foo'] = 'bar';

PHP:
// Page 2

session_start();
echo $_SESSION['foo'];
unset($_SESSION['foo']);
 
cheers for the reply.

I've tried it but when i add the code to my page I get this error

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs.........

is there something i need to know?

I've got a .php page with html in it as well. I've echo'd the html at the mo. I'm just trying to learn the php before i mess about with the design.

cheers again
 
You need to start a session before you output anything to the browser so you'll need that code before your html.
 
Back
Top Bottom