Jump to content

Passing Objects between brackets/pages


nathansizemore

Recommended Posts

Hello all!

I cannot seem to figure out a way to pass an object from one page to another.  Now, my flow may be way off, and if it is, please do advise.

I want to have a form for username/password log in.

When the submit button is hit, it takes those values, finds the matching user in the database, and returns the user object.  We'll call him user_object

Now, I want to bring up another page, that allows user_object to enter in additional information (Event details).  After it does this, it writes those Event Objects into the database. 

 

My problem is: I need the ID Object attached to user_object while inserting the Event Objects into the database.

The user_object and Event Objects values are assigned from two separate forms and two separate submit buttons. 

How do I pass this information?

 

I don't want to use session because I have a lot of objects and do not want to serialize and unserialize all the time.  I also read that $_GET is a security risk. 

 

Thanks in advance for any help!

 

This is the basic logic of the code I am trying:

<html form whatevs post>
<php
object_one        
if (creds_match)
{
	build_object from db
}
else "Wrong info, dude"
?></endhtml stuffs>

 

<html form whatevs post>
<php
object_two	
if (post!empty) 
{       
	object_two = poststuff
}
assign object_two object_one's _id
insert object_two into db
?></endhtml stuff>

 

How do I keep the values assigned in section one, and send them or be able to use that same variable in section 2?

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/261288-passing-objects-between-bracketspages/
Share on other sites

login.php:

<?php
if(isset($_GET['login'])){
echo 'Unable to log you in with the given username and password combination.<br/>';
}
echo '<form action="loggedin.php" method="post">
username: <input type="text" name="username" /><br/>
password: <input type="password" name="password" /><br/>
<input type="submit" name="submit" value="submit" />
</form>';
?>

 

loggedin.php:

<?php
$logged_in = false;
if(!empty($_POST['username']) && !empty($_POST['password'])){
// check if logged in
$logged_in = true;
echo 'logged in as:<br/>';
echo 'username: '.$_POST['username'].'<br/>';
echo 'password: '.$_POST['password'].'<br/>';
}
if(!$logged_in){
echo '<script type="text/javascript">
<!--
window.location = "login.php?login=error"
//-->
</script>';

// you may also use this, but no html must be sent to the browser before this for the redirect to work
// header('Location: login.php?login=error');
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.