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
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');
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.