Current location: Hot Scripts Forums » Programming Languages » PHP » Passing variables between 2 pages...


Passing variables between 2 pages...

Reply
  #1 (permalink)  
Old 05-09-06, 11:17 AM
RichLondoner RichLondoner is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Passing variables between 2 pages...

New to PHP and trying to pass a username and encrypted password from one php page to another.

Page 1 gets $username from a cookie which is made by our intranet system, then finds the associated $password from a user database and then encrypts the password to $encryptedpassword. Then $username is checked too see if the user exists in a forum i'm setting up (phpbb) and if not redirects to page 2 where the user is to be added automatically from the various variables.

Page 2 needs to read these variables so that I can automatically add the user.

Any ideas?

Thanks
Richard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-09-06, 12:06 PM
Barnz1986 Barnz1986 is offline
Aspiring Coder
 
Join Date: Jan 2006
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RichLondoner
New to PHP and trying to pass a username and encrypted password from one php page to another.

Page 1 gets $username from a cookie which is made by our intranet system, then finds the associated $password from a user database and then encrypts the password to $encryptedpassword. Then $username is checked too see if the user exists in a forum i'm setting up (phpbb) and if not redirects to page 2 where the user is to be added automatically from the various variables.

Page 2 needs to read these variables so that I can automatically add the user.

Any ideas?

Thanks
Richard
Use sessions.

First page: -

PHP Code:



session_start
();

$_SESSION['username'] = $username;
$_SESSION['password'] = $password
Second page: -

PHP Code:



session_start
();

$username $_SESSION['username'];
$password $_SESSION['password']; 
Third page: -

PHP Code:



session_start
();

$username $_SESSION['username'];
$password $_SESSION['password']; 
etc.

Last edited by Christian; 05-09-06 at 01:16 PM. Reason: Please use [PHP][/PHP] when positng PHP code!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-09-06, 03:14 PM
jonbeckett jonbeckett is offline
Newbie Coder
 
Join Date: Jan 2006
Location: UK
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I concur with the first answer - sessions will be the easiest method.

You could use POST too, but the advantage of sessions is you're keeping the data server-side too, so no sensitive data is travelling back and forth over the network.
__________________
Jonathan Beckett
http://www.pluggedout.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-10-06, 05:49 AM
RichLondoner RichLondoner is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
That didn't work at all, comes back with various errors:-

Warning: session_start(): Cannot send session cookie - headers already sent by (edit - file info)

Warning: session_start(): Cannot send session cache limiter - headers already sent (edit - file info)

Notice: Undefined index: username

Notice: Undefined index: password

Any other ideas, I think sessions and cookies won't work as I have code above where I need to see the session...

Thanks,
Rich
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-10-06, 05:54 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You have to place the session_start(); at the top of your page, before outputting anything to the browser.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-10-06, 06:00 AM
RichLondoner RichLondoner is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, that seemed to work for the first page, but I am still getting these errors on the second page when I try to read the sessions...

Notice: Undefined index: username
Notice: Undefined index: password

Thanks so far!
Rich
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-10-06, 07:41 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
just set error_reporting to E_ALL ^ E_NOTICE
it's just a notice, it's no big deal.
you can do this by placing this on top of EVERY page:
PHP Code:

error_reporting(E_ALL ^E_NOTICE);

// or you could use:
error_reporting(2037); 
you could also edit your php.ini file: look for error_reporting and give it the value E_ALL ^ E_NOTICE

if you do want to use the NOTICE reportin use this code:
PHP Code:

session_start();

$username "username";
$password "password";
session_register("username""password"); 
you might wonna read this page about sessions:
http://be2.php.net/manual/en/functio...n-register.php

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 05-10-06, 08:02 AM
RichLondoner RichLondoner is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks all...

Page 1 :

session_start();
session_register("username", "password");

& later on in another bit of code did:

$_SESSION['username'] = $dpusername;
$_SESSION['password'] = $encryptedpassword;

Page 2 :

session_start();
$Username = $_SESSION['username'];
$Password = $_SESSION['password'];

and then echoing the $username/$password seemed to work great as I can now pass the username and encrypted password from page to page...

Thanks guys, I maybe back at one point!
Rich
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 05-10-06, 10:30 AM
Alli Alli is offline
Newbie Coder
 
Join Date: May 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
it's better to use cookies than session, as i think
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 05-10-06, 11:19 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Quote:
Originally Posted by Alli
it's better to use cookies than session, as i think
why's that?

session are destroyed when a user closes it's window, unless otherwise defined in the server settings.
cookies remain on the user's computer till they expire

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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
Passing javascript variables to new page... Tim Mousel JavaScript 1 01-29-05 04:23 PM
Passing info between pages w/ URL HairySpider JavaScript 6 01-09-05 09:47 AM
sending variables between pages ? shadi PHP 6 08-20-04 08:38 AM
sharing global variables accross pages davidklonski JavaScript 1 05-24-04 03:06 AM
PAssing variables dbalka Perl 3 10-29-03 06:00 PM


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