problems with cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

problems with cookies

Post by sebs »

I need to transfer one cookie to a third page.As I understood the cookie needs to be set before any output.The problem is that I need to transmit through that cookie on what it has been clicked.Can you help me?Is there a way to know from which page you have been redirected to the curent one?
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Re: problems with cookies

Post by chrys »

sebs wrote:I need to transfer one cookie to a third page.As I understood the cookie needs to be set before any output.The problem is that I need to transmit through that cookie on what it has been clicked.Can you help me?Is there a way to know from which page you have been redirected to the curent one?
You should look into sessions.

http://www.php.net/session_start

It basically goes like this:

put session_start(); at the very top of every page in your site.

To register a variable, set it like this:

$_SESSION['var'] = "john";

Then on your next page:

echo $_SESSION['var'];

Output will be:

john

Just make sure to have session_start at the top of the page before any output.
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

ok,but if I do that it gives me a php error in windows and still not working.I'm using phptriad with a new php,I think 5.And I can't put on the very top of every page because I have some static pages between them
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

sebs wrote:ok,but if I do that it gives me a php error in windows and still not working.I'm using phptriad with a new php,I think 5.And I can't put on the very top of every page because I have some static pages between them
Could you paste the error?

Are you running this off of IIS or Apache in Windows?
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

I am running apache.the error that gives windows XP(all errors of windows are given the same)only that it sais php.exe created the error.
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

is there any variable in which is kept the files name (the file is static) that redirected me to the current page?
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

sebs wrote:I am running apache.the error that gives windows XP(all errors of windows are given the same)only that it sais php.exe created the error.
Ah it's an executable error... that's really weird, and it shouldn't be doing that because of PHP code. I have no experience with windows apache, so I Can't help there. But let's take a look at the code. Can you paste the code for the file that is crashing?
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

<?php
session_start();
echo $_SESSION['search'];
?>
This is in the third page!
And in the first page I have:
<?php
session_start();
$_SESSION['search'] = "1234";
...//sql query that is working ok;
?>
session_start() it's put on every file at the start of file write?
Sorry I answered so late
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Please use

Code: Select all

tags for posting PHP code and

Code: Select all

tags for other code or output 

If you are receiving executable errors with php.exe, you have either a corrupt Apache installation, corrupt PHP installation, corrupt Windows installation or any combination of the above.

Fix those, else you will forever receive errors that you will think is your code
Post Reply