Page 1 of 1

Trying to transfer a value from one page to the next

Posted: Sun Aug 26, 2007 2:20 pm
by DRandy
Hi

I've been working in php now for about 1 year, trying to teach myself. I took a 4 day php class but that just made me realize how much there is to learn. The mud is clearing very very slowly. I've been basically doing trial and error editing, tweaking my Wordpress 2.1 and because it is just too time consuming to keep trying to go it alone, I finally registered here.

So this is what I am trying to do right now.

I have a page that displays a sigle post in Wordpress. One of the template tags is:

Code: Select all

<?php the_ID(); ?>
This tag represents the id of the post. I want to transfer this id and use it on the login page which also acts as a registration page when action=register is called.

My objective is to have the id populate the field at all times. Sometimes people might click submit without filling out all required fields. I found that the_ID would not repopulate when that occured.

So what I did was create a link:

Code: Select all

<a href="http://www.mysite.com/login.php?action=register&postid=<?php the_ID(); ?>">Register</a>
Then on my login page, I add at the top of the file:

Code: Select all

<?php

session_start();
$_SESSION['postid'] = $_GET['postid'];
$registeringpostid = $_GET['postid'];
ob_start();

and then some other code...
I also add a new field within the registration form:

Code: Select all

<p>
<label><?php _e('ID #:') ?><br />
<input type="text" name="postid" id="invite" class="input" value="<?php echo $registeringpostid ?>" readonly="readonly" size="20" tabindex="10" /></label>
</p>
(I want to associate the_ID of the post for those that registered through it so eventually I have to get this in the database - but thats a hurdle I'll deal with later.)

I've looked into the sessions idea and tried to do the session_start on the post page because it just seems more logical and reliable. But the php function for "the_ID" starts within the loop and the session_start begins before any headers or functions.

How do I get the value of "the_ID" in the session_start from that same post page so it can be used in the pages that follow? (The id changes for each new post)
Is this the most efficient way to handle this?
Is there any problem with the way I did it?

My php info:

PHP Version: 5.1.6
Display Errors: On
Error Level: Not E_ALL
Register Globals: On

Thank you for helping. I hope someday I'll be able to give back.

Posted: Sun Aug 26, 2007 2:51 pm
by julian_lp
I guess your question has more to do with WordPress coding rather than Php. I've tried to modify WordPress code (I was successfull in many cases) and I think it's not the best code one could work on to learn. It uses many globals, the program flow isn't as clear as one would want. It's just my opinion, I've heard people talking very good things about WP coding style. I like WP as a blog application though :)
Anyway, hope you can find what you're looking for. Sadly I've forgotten every single line I wrote for WP so I'm unable to help you :(

Posted: Sun Aug 26, 2007 3:04 pm
by DRandy
My question is more php rather than specific Wordpress.

It is about getting a value into session_start.

I know how to declare a value and put it into session_start. But what about a value that changes based on the individual post.

Do you create a function within session_start?