Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Values to another Page w/o a Form

Status
Not open for further replies.

estrellas

Programmer
Jul 16, 2004
48
0
0
US
Hey guys -

I"m working with a lot of php/mysql databases here, and in order to update account information here's the code we use ...

Code:
	printf ("\n<form method=\"post\" action=\"mailadd.php\">\n");
	printf ("<input type=\"hidden\" name=\"geo_type\" value=\"rectangle\">\n");
        if ($usecookies == 0) {
	  printf ("<input type=\"hidden\" name=\"userid\" value=\"%d\">\n", $userid);
	  printf ("<input type=\"hidden\" name=\"passwd\" value=\"%s\">\n", $passwd);
        }
#	echo '<input type="Submit" name="submit" value="Enter a rectangle mail rule">';
	echo '<input TYPE="image" src="button-rectangle.jpg"></form><br>';
	echo "</form>\n";

now...my job is to redesign this site, etc, and to make it where we don't need the forms to send information from page to page.

How do you do that? I really don't know that much about php to know how to do it.

Thanks much in advance.

 
You can use sessions or pass them in url

URL:

Sessions:
Code:
//Used to initialize the session superglobal
//Must be the first line on the page and must be done
//on every page you use session data on
SESSION_START();

//Puts $value into the session section "variable.name"
$_SESSION['variable.name'] = $value;

//Retrieves the value from session data
$value = $_SESSION['variable.name'];
 
I agree with Matt, use sessions. Passing a URL can be very ugly, people bookmark them and as it is limited in length.f you have a cluster of servers you will have to use a database based session handler rather than the default file implementation.
 
okay .. forget that last post then (sorry i didn't seee your new post igresman)... i'll learn about using sessions!

thanks much!!

-------
 
if you do go the URL route your example is alomist correct as far as code goes but it sohuld like like
as by the timethis happens php has droped out of the picture and real values need to be seen.
As you will know passing clear text passwords in clear view is not so good !!
 
Going with session variables makes your URL 'prettier' and avoids probing by crafting specific URL parameters.

All you need is to start each script with session_start():
Code:
<?php
session_start();

# assign var:
$_SESSION['myVar'] = 'whatever';

# retrieve (in any script that uses session_start()):
echo $_SESSION['myVar'];
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top