yrrahxob Posted September 17, 2006 Share Posted September 17, 2006 I am building my own web site and on the main page, there is an option to login to a users' account if they so desire. This is not a requirement. After they login, they can browse through products and and then to the shopping cart. When they are ready to checkout, they are presented with a form asking for name and address and other information. What I want to do is when the form is presented and they are logged in, the form will be populated with the information retrieved when they logged in.below is the validation/login script I am working on. I want to keep the values of the array $user_info during the entire session and I have register_globals disabled. Someone please help.<?phpfunction validate_user($user_email, $user_password){ $row=array(); $q = db_query("SELECT ss_first_name, ss_last_name, ss_email, ss_phone, ss_address_1, ss_address_2, ss_city, ss_state, ss_zip_1, ss_zip_2 FROM ".USER_TABLE." WHERE ss_email='$user_email' AND ss_password='$user_password'") or die (db_error()); $row = db_fetch_row($q); return $row;}if(isset($_POST["login_submitted"])){ $user_info=validate_user($_POST["user_email"], $_POST["user_password"]);}?> Link to comment https://forums.phpfreaks.com/topic/21064-retaining-variables-accross-pages/ Share on other sites More sharing options...
Daniel0 Posted September 17, 2006 Share Posted September 17, 2006 In order to ratin variables across pages you could use sessions.Put [code]session_start()[/code] before anything is output (eg on the top of the page) and define the variables like $_SESSION['something']. You would then be able to call it on another page (which has ran session_start() too) as $_SESSION['something']. Link to comment https://forums.phpfreaks.com/topic/21064-retaining-variables-accross-pages/#findComment-93519 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 lookup sessionsquick example.test.php[code]<?php session_start();$name="redarrow";$name=$_SESSION['name']=$name;echo"<a href='test_result.php'>please see my name</a>";?>[/code]test_result.php[code]<?php session_start();echo"Hello there my name is $name";?>[/code] Link to comment https://forums.phpfreaks.com/topic/21064-retaining-variables-accross-pages/#findComment-93520 Share on other sites More sharing options...
Daniel0 Posted September 17, 2006 Share Posted September 17, 2006 I don't think that would workThis will work:test.php[code]<?phpsession_start();$_SESSION['name'] = "something";echo"<a href='test_result.php'>please see my name</a>";?>[/code]test_result.php[code]<?phpsession_start();echo "Hello there my name is {$_SESSION['name']}";?>[/code] Link to comment https://forums.phpfreaks.com/topic/21064-retaining-variables-accross-pages/#findComment-93527 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 mine does work i think your getting confused as i set the session with the varable name. Link to comment https://forums.phpfreaks.com/topic/21064-retaining-variables-accross-pages/#findComment-93531 Share on other sites More sharing options...
wildteen88 Posted September 17, 2006 Share Posted September 17, 2006 [quote author=redarrow link=topic=108394.msg436046#msg436046 date=1158505296][code]<?php session_start();$name="redarrow";$name=$_SESSION['name']=$name;echo"<a href='test_result.php'>please see my name</a>";?>[/code][/quote]Why on earth would do [code=php:0]$name=$_SESSION['name']=$name[/code] for? I see no logic in that. Link to comment https://forums.phpfreaks.com/topic/21064-retaining-variables-accross-pages/#findComment-93632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.