Current location: Hot Scripts Forums » Programming Languages » PHP » sending variables between pages ?


sending variables between pages ?

Reply
  #1 (permalink)  
Old 08-18-04, 06:31 PM
shadi's Avatar
shadi shadi is offline
Wannabe Coder
 
Join Date: Aug 2004
Location: EGY
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
Question sending variables between pages ?

i want to know if there is another way else creating hidden fields or url?variable=value ?

because if i wan't variable to be used in all the pages , i'll had to create a hidden field in each page contains the same value and the same name.

but this method is suck !!


so if any one know any way please tell me

thanks
Reply With Quote
  #2 (permalink)  
Old 08-18-04, 06:43 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Sessions or cookies seem like a good alternitive.
Reply With Quote
  #3 (permalink)  
Old 08-20-04, 01:23 AM
Aesis's Avatar
Aesis Aesis is offline
Newbie Coder
 
Join Date: Aug 2004
Location: Kimberley B.C.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
sessions

I think sessions would be the best answer to your problem like Eclipse said ,

All you need to do is place a
PHP Code:

<?php
session_start
();
?>
at the very top fo your page before any data is sent out to your browser or you'll get some nasty errors then just register your variable.

Registering the Session:
PHP Code:

<?php
session_register
('variable');
$_SESSION['variable'] = $foo
?>
and now wherever there is a page with sessions started you can use "$_SESSION['variable']" all over your page ^_^
__________________
Aesis - w00t
http://img36.exs.cx/img36/4426/kawaii1.gif
Reply With Quote
  #4 (permalink)  
Old 08-20-04, 02:41 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Aesis
Registering the Session:
PHP Code:

<?php
session_register
('variable');
$_SESSION['variable'] = $foo
?>
Quote:
Originally Posted by YourPHPpro
CAUTION: If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
http://www.php.net/manual/en/functi...on-register.php
just a quote to a reply i got few months ago
Reply With Quote
  #5 (permalink)  
Old 08-20-04, 03:22 AM
shadi's Avatar
shadi shadi is offline
Wannabe Coder
 
Join Date: Aug 2004
Location: EGY
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
sessions ?

i think sessions will not be good , it isn't flexible at all !
because i'll start sessions every time i want to register a variable when the opreation ends i'll had to close it

it will be hard to me comparing with the method post as example !

thanks
Reply With Quote
  #6 (permalink)  
Old 08-20-04, 04:50 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by shadi
i think sessions will not be good , it isn't flexible at all !
because i'll start sessions every time i want to register a variable when the opreation ends i'll had to close it

it will be hard to me comparing with the method post as example !

thanks
well.. i personally think that sessions are the best solution for saveing variables for multiple pages.. but if you dont want to use them then.. well leaves you with cookies. a page that might be usefull:
http://fi2.php.net/manual/en/features.cookies.php

hope it helps
Wille
Reply With Quote
  #7 (permalink)  
Old 08-20-04, 07:38 AM
Dion's Avatar
Dion Dion is offline
Newbie Coder
 
Join Date: Jun 2004
Location: NL
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
you can also use the include() function, here is a example

every page where you need the variables:
PHP Code:

include_once ("./settings.php");


$dbh mysql_connect($hostname$username$password
    or die(
"Unable to connect to MySQL");


$selected mysql_select_db($base,$dbh
    or die(
"Could not select database"); 
settings.php:
PHP Code:

<?

# Root MySQL database
$base "xxx";
# MySQL user name
$username "xxx"
# MySQL password
$password "xxx";
# Host name (ex. localhost)
$hostname "xxx";
# Main Table name (ex. mysite)
$basesites"xxx";
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to link to insert pages samkry ASP 0 06-13-04 11:14 PM
sharing global variables accross pages davidklonski JavaScript 1 05-24-04 02:06 AM
1500 pages PR6 website for sale Ozza Traffic Exchange 0 03-24-04 02:42 AM
help with displaying variables tisza PHP 9 12-22-03 05:08 PM
How to convert php generated pages to SE friendly HTML or PHP(SE friendly) -CLASS 101 crippled PHP 1 11-16-03 06:37 AM


All times are GMT -5. The time now is 04:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.