Forum Moderators: coopster

Message Too Old, No Replies

Calling A Variable Across 2 Pages

         

Programmers

10:44 am on Jul 6, 2006 (gmt 0)

10+ Year Member



Basically, I have two pages that I want to transfer a variable across. The below might make things a little more clear:

Page one has a title and some stuff, and a link to page two.
Page two has a form for the user to fill in and submit.

Page one is different – it depends on which one the user chooses.
Page two is the same page – it is linked from all the different page ones.

To be certain of where the user came from, I would like to call a variable called $title from page one onto page two.

Any help would be greatly appreciated.

Regards,
Tom.

Sekka

11:24 am on Jul 6, 2006 (gmt 0)

10+ Year Member



You could do this many ways. I have included 2 examples.

Either,

When page 1 is loaded, set the title in the session, and when page 2 is loaded, just get the title from the session.

Or,

Pass the title as a GET variable on the URL.

e.g. The link to page 2 would be "page2.php?title=lalala"

Programmers

1:57 pm on Jul 6, 2006 (gmt 0)

10+ Year Member



Okay, I've just tried the second suggestion because I don't understand sessions yet.

The url was index.php?get=folder/page.php&title=name

And it worked. However! This link is a global link and is used everywhere on all the one pages. Is there any way I can set it to call the title rather than pre-write it?

Programmers

2:27 pm on Jul 6, 2006 (gmt 0)

10+ Year Member



I've done it. I've solved the problem myself! It's such a better feeling when you work something out on yer own. Although, I was prepared for help.

To the global url I did this:

<a href="index.php?folder/page.php&title=<?php echo $title?>"> And it works a treat now.

Thanks for the help. =)

eelixduppy

2:52 pm on Jul 6, 2006 (gmt 0)



If at all possible for you, it is recommended that you set register_globals [us3.php.net] to off if you don't have it that way already. It may not present an issue here, but may cause one down the road. Good luck!

Programmers

3:09 pm on Jul 6, 2006 (gmt 0)

10+ Year Member



What do you mean?

eelixduppy

3:12 pm on Jul 6, 2006 (gmt 0)



If you go to the link in msg #5, it explains how having register_gloabls on can lead to security problems. I just figured that you had it set to on by the way you have your code, however I may be wrong. I would just suggest reading about it anyway to get familiar with it. Hope this helps ;)

Programmers

3:59 pm on Jul 6, 2006 (gmt 0)

10+ Year Member



Thank you very much. I'll give it a read.