...

View Full Version : php help signupdate/script



simon99
02-15-2010, 02:41 PM
I am trying to create a membership site that has gradual content release. There are very few programs out there that do this and none that do what I want.

What im looking for/need help with.

I want links to appear on a main page depending on how long a user has been a member.

so for example...

day 1 user can see link1
day 2 user can see link1 and link2
day 3 user can see link1 and link2 and link3

i have found a script that could me modified but i am having trouble with it.

my php knowledge is very limited and would greatly appreciate someone either guiding me through it or possibly writing it for me if its not a big job.

here is the script

<<?php

// Init. Get current user status, data + connect to database and such
include('common.php');

$signupdate = "Huh??";

$lesson[0] = "day 0 stuff";
$link[0] = "day0.php";
$desc[0] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sagittis ipsum at lorem. Suspendisse feugiat. Sed imperdiet orci at magna.";
$days[0] = 0; // for immediate

$lesson[1] = "day 1 stuff";
$desc[1] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sagittis ipsum at lorem. Suspendisse feugiat. Sed imperdiet orci at magna.";
$link[1] = "day1.php";
$days[1] = 1; //

$lesson[2] = "day 2 stuff";
$desc[2] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sagittis ipsum at lorem. Suspendisse feugiat. Sed imperdiet orci at magna.";
$link[2] = "day2.php";
$days[2] = 2; //

$lesson[3] = "day 3 stuff";
$desc[3] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sagittis ipsum at lorem. Suspendisse feugiat. Sed imperdiet orci at magna.";
$link[3] = "day3.php";
$days[3] = 3; //

$lesson[4] = "day 4 stuff";
$desc[4] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sagittis ipsum at lorem. Suspendisse feugiat. Sed imperdiet orci at magna.";
$link[4] = "day4.php";
$days[4] = 4; //

//BEGIN Output, Display, Echo

include 'header.php' // top of page
?>
<h1>Your Lessons</h1>

<?php
$seconds_a_day = 86400;
for($i = 0; $i < count($lesson); $i++)
{
$days_to_release = $days[$i] * $seconds_a_day;
$release_date = $signupDate + $days_to_release;
$j = $i + 1;
if ($release_date > time())
{
echo "<p style='color: #999;'><strong>Lesson ".$j.": ".$lesson[$i]."</strong>
".$desc[$i]."
available to you on ". date('l jS \of F Y', $release_date) ."</p>";
}
else
{
echo "<p><strong>Lesson ".$j.": <a href='".$link[$i]."'>".$lesson[$i]."[/url]</strong>
".$desc[$i]."
Content released on ". date('l jS \of F Y', $release_date) ."</p>";
}
}

//More CONTENT GOES HERE

include('footer.php'); // the bottom of page

?>

this script will allow users to click on each link depending on how many days they have been a member.

what I would like(if possible) is for the links to be hidden until the selected day the links become active.


another problem i am having is is wont read or find common.php


where would this file be on my server/database and if i created one, what code would i put in it and where would i find the code for it.

at the moment it is displaying the date as 1st jan 1970

I hope someone can help me

thanks

mlseim
02-15-2010, 04:30 PM
Do you already have a database (MySQL) set up where the user registers?
So, they register with a form, it's verified with their email address, and they
can then access a profile page? You'll know when they registered, and can
work from there.

How much do you already have set-up as it pertains to the membership part?

simon99
02-15-2010, 07:01 PM
yes I have a database setup with mysql.

My server has all the latest software and programs etc so its not limited by the server capabilities.

yes they sign up to the membership site then get transfered to the 'main page'

what im looking for is a way to display links/new pages after a set times.

is there a way of hiding links then displaying them after eg 2days after becoming a member?

ive asked at alot of forums but havent really got very far. people have mentioned using $signupDate but this doesnt seem to work with this script.

All I want is a script that checks current date and signupdate, calculates days since membership started then displays/allows links accordingly.

I would prefer if it hid links then displayed after a set date.

My php knowledge is very limited and my funding is also limited otherwise I would pay someone to build one for me.

is config.inc.php something to do with finding the members info?

is this being used instead of $signupDate? - (intval($_SESSION['_amember_id'])

is header.inc.php different to header.php?

im sorry for all the questions. I do look for answers on the internet before asking in forums and I know that i shouls steer clear of php if i dont know what im doing, but i really need this working.

hope you can help

thanks

JAY6390
02-15-2010, 07:09 PM
You can subtract the signup time from the current time and work out the difference between the two, then echo out the relevant link(s) dependant on that value

mlseim
02-15-2010, 08:18 PM
What is the variable name you have in MySQL for the "sign up date"?
And what is the format of that date (mm/dd/yyyy, or ??? )?

simon99
02-15-2010, 11:13 PM
where would i find the variable for the sign up date in mysql?

sorry, im new to all of this.

simon99
02-15-2010, 11:17 PM
You can subtract the signup time from the current time and work out the difference between the two, then echo out the relevant link(s) dependant on that value

that is what the code i posted does. The problem im having is its not collecting data from the $signupDate or whatever the amember equivelant is and its not using the correct unix date. keeps refering to jan 1st 1970.

Plus I want to find out how to make links visible after a certain time period - if its possible.

simon99
02-15-2010, 11:23 PM
How much do you already have set-up as it pertains to the membership part?

The whole site is complete and fully functional. The only thing im missing is the gradual content script.

JAY6390
02-16-2010, 12:11 AM
You say the whole script is set up but where is the code that gets the signup date? You need to get the signup date, and find out what format it is presented in (ie UNIX timestamp, or mysql date time format). If it's the latter, get the date using the UNIX_TIMESTAMP (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp) function along with your column

mlseim
02-16-2010, 01:01 AM
You have to query the database to find the sign-up date for a particular user.
That sign-up date is a variable in your MySQL database (table). No way to give
you an example of how to do it unless we know what the variable (field name) is.

In fact, you need to have some scripting to query the database to begin with.
I think you're missing a lot of code ... or are not showing it to us.

Without knowing when the user signed-up, how can we compare any dates?

EDIT:
If you show us any MySQL connection scripting, remove the username and password so we can't see it.
If you want, you can PM me and I can give you more information (as you can provide me with more private data).



.

simon99
02-16-2010, 08:20 AM
The script I have posted uses the signupdate and time etc to release content but like you both rightly said, there is code missing.... this is what I am stuck on.

I dont know where to get this code from.

I have searched my files on the server in a blind attempt to find what you ask.
I hope one of these code help.

$product = & get_product($product_id[0]);
$begin_date = $product->get_start();
$expire_date = $product->get_expire($begin_date, null, $terms); //yyyy-mm-dd

$pc = array();
$pc['db'] = '??????';
$pc['user'] = '???????';
$pc['pass'] = '???????';
$pc['host'] = '???????';
$pc['prefix'] = '???????';
$pc['charset'] = ''; // replace with 'utf8' for example

$config = array();
$config['db']['mysql'] = $pc;
$config['use_mysql_connect'] = 1;
$config['root_dir'] = dirname(__FILE__);

the ??? are details I have edited.

Is any of the above the right information?

Is the $begin_date used instead of $signupDate? or is that to do with product? although there is only 1 product and will onlt every be 1 product

hope this helps and I thank you for your patience with me

simon99
02-16-2010, 09:16 AM
so basically I need to send a query to the database?
and this gets added to header.php?
so that all pages get info?

I tried including common.inc.php but its still returning 1970 despite trying different codes.

Its not easy to find php basic info on the net.

mlseim
02-16-2010, 01:02 PM
Do you know the name of the script you're using for members?
Is there some pre-made script you found that you're using?

Show us "common.php", but remove any MySQL passwords that are shown.

simon99
02-16-2010, 01:10 PM
the script im using for the 'gradual content' is one I found on a forum but its made for dlguard. but it will work if i can get the query working.

I dont have a common.php file, only a common.inc.php file.

does a common.php file need to be created?

If its going to cause problems, i can abandon the script and use another one.

at the moment i have a simple script to display current time but even thats not displaying the right time.

This is due to the database not being accessed?

mlseim
02-16-2010, 01:21 PM
If it's using a MySQL database, then somewhere it needs to connect to it.

Did you install it yourself?
Do you remember setting up a MySQL database with your webhost control panel?

simon99
02-16-2010, 01:27 PM
yes I installed it myself.

Yes I set up the database with my hosting.

I think it created the tables when it installed.

simon99
02-16-2010, 01:32 PM
I have logged into mysql and there are 25 db's set up on there.

am i able to get the info I need from them?

mlseim
02-16-2010, 01:35 PM
So now, using your webhost control panel, you can enter your MySQL database
with the MySQL Admin and view the table(s) it has created. You can browse those
tables and see the names of each field (or variable) it has, along with the format.

So, we want to know the name of the variable that contains the "start date" of the member.
You can look at a couple of records to see what the date format is.
Is it like, 1263471232 ... or like, 2010-02-16 ... or like, 20/16/2010?

We need to know what the name of the variable is, and how it's formatted.

simon99
02-16-2010, 01:39 PM
field - added
type - datetime
null - no
default - 0000-00-00 00:00:00

this is the field that contains the start time of member.

thank you for being so patient with me

mlseim
02-16-2010, 01:45 PM
So the variable name is called 'added'.

And if you happen to have any actual records of real members in your database,
view a couple of them and see if there are REAL dates in the records.
If all of them have the value of "0000-00-00 00:00:00" ... then you have other problems.

If all of the members have REAL dates, let me know that too.

=====================

Next ...

You must have a place where the member logs in?
So when they log in, you know who they are, and this will be the place where you
find out what that "added" date really is. You need to find-out what the name of
the script is that logs-in the user, and show us a listing of that script. Perhaps they
call it "login.php"?

simon99
02-16-2010, 01:59 PM
Have checked the db and users have an actual 'added' date in there so that is working.

this is the content of the 'login.php' file



if (@$_GET['_test_'] != '' ||
in_array(@$_GET['_test_'], array('file', 'root_url', 'root_surl'))){
header("Content-type: text/javascript; charset=UTF-8");
echo $_GET['_test_'];
exit();
}

include('./config.inc.php');
$t = & new_smarty();
$_product_id = array('ONLY_LOGIN');

if (isset($_REQUEST['amember_redirect_url']))
$_SESSION['amember_redirect_url'] = $_REQUEST['amember_redirect_url'];

function rcmp_begin_date($a, $b){
return strcmp($b['begin_date'], $a['begin_date']);
}

include($config['plugins_dir']['protect'] . '/php_include/check.inc.php');
$payments = & $db->get_user_payments(intval($_SESSION['_amember_id']), 1);
usort($payments, 'rcmp_begin_date');

$now = date('Y-m-d');
$urls = array();
foreach ($payments as $k=>$v){
if (($v['expire_date'] >= $now) && ($v['begin_date'] <= $now)) {
$p = get_product($v['product_id']);
$url = $p->config['url'];
if (strlen($url)){
$urls[] = $url;
}
}
}

if ($_SESSION['amember_redirect_url']) {
$redirect = $_SESSION['amember_redirect_url'];
unset($_SESSION['amember_redirect_url']);
} elseif (count(array_unique($urls)) == 1){
$redirect = add_password_to_url($urls[0]);
} else {
$redirect = $config['root_url'] . "/membership-home.php";
}
#print_r($urls);
html_redirect("$redirect", 0, 'Redirect', _LOGIN_REDIRECT);
?><?php include('footer.php'); ?>

mlseim
02-16-2010, 02:47 PM
So, it looks like they are using the "smarty" system. That makes things harder for us.

Smarty is a system where it allows the site designers and program developers to
work together without affecting each other's areas. So everything is done in modules
and plug-ins. Great for developers, but harder for us "hackers" to change things.

We still are not at the "root" of the part where the database is connected.

PM (Private Message) me with the listing for "config.inc.php" ... don't post it here because there might
be account information in it. I think it's in that file where the database is actually
connected. We need to get the 'added' variable put into a session variable so we
can use it later on (to find the differences in dates).

simon99
02-16-2010, 05:11 PM
Went onto mysql and asked for php code for 'added'

it gave me this, is this any good?

$sql = 'EXPLAIN SELECT `added` FROM `amember_members`';

simon99
02-16-2010, 05:27 PM
I dont know if this will help

http://manual.amember.com/Using_site.inc.php_and_hooks#aMember_database_functions

mlseim
02-16-2010, 05:40 PM
Simon ...
We're so close.

Look at your admin section, or member section and see if they
have anywhere that shows when the user was added. Maybe they
are using the same field for something else, and we can copy the
way that they access the value for the member that is logged-in.

Specifically, log-in as a member and hopefully there's a place on
a page that says ("you've been a member since December 13, 2008").
If that ever shows up for a logged-in member, we would be home free!

simon99
02-16-2010, 06:17 PM
I know this one is regarding user payments, but can this be altered for 'added' or member_id?

global $db;
$pl = array();
$dat = date('Y-m-d'); // get today date in SQL format
foreach ($db->get_user_payments($member_id, 1) as $p){
if (($p['begin_date']<=$dat) && ($p['expire_date']>=$dat)){
$pl[] = $p;
}
}
// now $pl contains only completed and non-expired payments
print_rr($pl, 'active payments');

$u = $db->get_user($user_id)

This function will return you a user record for given user_id

mlseim
02-16-2010, 06:18 PM
Simon ...

Let's try an experiment ...

On one of the pages that displays after the user logs-in, add these lines ...

$testing = $_SESSION['_amember_user'];
if ($testing['member_id'] > 0){
print "You have been a member since: $testing[added] <br>\n";
}

Now, log-in as a member and view that page ...
see if it displays the date that the member was added.

Let me know if you see a correct date.

If this works, it will be the way in which we can get that date and then
we can start doing the date calculations that you need.

simon99
02-16-2010, 06:57 PM
that didnt work,

but i found this script online and added it and it displayed todays date correctly

$nextWeek = time() + (7 * 24 * 60 * 60);
// 7 days; 24 hours; 60 mins; 60secs
echo 'Now: '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
// or using strtotime():
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";

so its collecting the time correctly from the db or sql.

can we work on this to get the other piece working?

mlseim
02-16-2010, 07:25 PM
You're getting the date correctly as "today's date" ...
But how do you know when the member was added?

The date/time you're using is not from the database, it's from today's date.

That's the part I'm trying to figure out. When a member logs-in,
we need to find out when they were added by finding that in the database.

Your script author (amember.com) has a forum. Maybe you can ask someone
there how to access the date of when the person was added.

Once we can find the date when the member was added, we can do the
calculations between their added date and today's date.

simon99
02-16-2010, 07:43 PM
Ive been reading through the amember manual and it says its based on subscription date and not added date.

Note: Once a user has been added as a member, they will be able to access their member page at http://www.yoursite.com/amember/member.php , using the username and password in their member record. However adding a user as a member does not give access to any content, you must subscribe user (add a payment).

mlseim
02-16-2010, 07:54 PM
Well, does that mean what you want to do won't work?
You need to know when they were added.
I guess there's not much you can do then?

simon99
02-16-2010, 08:47 PM
it means instead of using added date, have to use subscribe date.

Its really giving me a headache. its been days of hastle with this.

Might just have to give in and admit defeat.

thank you so much for your help and support, its much apreciated.

will see if i can get their gradual content plugin to work.

thanks again

mlseim
02-16-2010, 09:55 PM
What does "subscribed date" mean?
Is that something that is related to when they became members?
Or does that change all the time?

If that date is not important to you (as the original function of it), maybe you can make it so that
it never changes again ... and use it for your own purpose.

simon99
02-16-2010, 10:11 PM
I have installed another, simpler membership script on another site just a minute ago.

Its alot simpler but was wondering if i can do the same thing on here.

It just uses sessions

here are the details.

<option value="date_of_join">Date of Join (yyyy-mm-dd)</option>

$sql = "SELECT * FROM members WHERE date_of_join LIKE '$m_today'";

echo "<td>".$row['date_of_join']."</td>";

$sql = 'SELECT COUNT( * ) AS `Rows` , `date_of_join` FROM `members` GROUP BY `date_of_join` ORDER BY `date_of_join` LIMIT 0, 30 ';

how would i use the bit of code you wrote earlier?

simon99
02-16-2010, 10:17 PM
I tried this but didnt work
i dont know if you wrote it in smarty or sessions

is it right or have i just made it up?
<?php
session_start();
$testing = $_SESSION['date_of_join'];
if ($testing['subscriber_id'] > 0){
print "You have been a member since: $testing[date_of_join] <br>\n";?>

mlseim
02-16-2010, 11:49 PM
The bit of code earlier was an example from the other site's faq pages.
Your new script will be somewhat different.

What is the name of the script you're using now, and where did you download it?

With this new script, when a member is added to the database, I assume there
is a date of when they joined? Now, just like the old script, when the member
logs in, we need to grab that join date from their record on the database.

simon99
02-17-2010, 12:00 AM
well ive managed to get the incremental plugin working for amember now. so i dont need the script anymore.

the only problem is its saying i dont have permission to access files when i click on the links i created with it. the file is set to chmod 777 and it still wont let the me/members go through the link.

any ideas?

i know this might not be your area of expertise but you know alot about php so just wondering if you have any idea.

I cant get help from service desk or amember forum.

cheers

mlseim
02-17-2010, 12:08 AM
Is the error message a PHP script error (failure) ... such as "no file permission",
or is it an error that the program gives you? Meaning there is something about
the member's settings that won't let them go through?

Is "it" the server or the amember program?

simon99
02-17-2010, 12:29 PM
it says forbidden, you dont have permission to access fileA/test/ on this server

I have the folder set to chmod 777 so there shouldnt be an issue there. unless its something to do with including a file in ht epage like conmfig.inc.php or common.inc.php

very confusing

also out of curiosity, how do i get the .css file to stop being over written by the header.php file. it seems the header is deciding what colour the page should be.

mlseim
02-17-2010, 01:03 PM
CSS is commanded in the order in which the tags (or properties) are loaded.

That means your header.php file must be getting loaded after your .css file.
It may not appear that way physically (when you view your script), but when the
PHP file is processed and sent to the user's browser, the server may be processing
the PHP scripts last, so the included "header.php" file may be the last CSS it sees.

If you do an inline CSS property, you can force the colour another direction ...

<body style="background-color:#8a8a8a;">


=================================================

The forbidden problem ...
I wonder if there's some .htaccess thing in-place that causes that.
Find a way to create a "test" folder with some files and test it using another script.
If you can duplicate the problem, you might find a solution.

simon99
02-17-2010, 03:10 PM
Its ok, its sorted now.

problem was that there was no index.html in the file

I did think it was strange that it was opening to a folder and not a file.

they really should be more accurate in their instructions.

the link script they gave way wrong too, had to find a copy on the web.
All sorted.

Thanks alot for your help and support over the past couple of days.

much apreciated.

thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum