Mysql php checking paid field
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah | Please use
Everah | Removed potentially sensitive information.
Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]Code: Select all
<?php
include("top.php");
//top.php is the database connection settings only, along with a welcome username and 3 image links
session_start();
if (isset($_SESSION['Paid']))
{
if ($_SESSION['Paid'])
{
// Let me in!
}
else
{
header("paidonly.php");
exit;
}
}Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
OK, first thing, please use the appropriate bbCode tags when posting code. I have cleaned this up for you a few times.
Next, try this...
Next, try this...
Code: Select all
<?php
include("top.php");
// top.php is the database connection settings only,
// along with a welcome username and 3 image links
// Start the session here
session_start();
// First things first, check the paid session var
if (isset($_SESSION['Paid']))
{
// Ok, the session var 'Paid is set
if ($_SESSION['Paid'])
{
// Session var 'Paid' is true (or 1)
// Let me in!
}
else
{
// Session var 'Paid is false (or 0)
// Redirect to A FULL URL AS PER THE MANUAL
header("Location: http://www.mysite.com/paidonly.php");
exit;
}
}
else
{
// Session var 'Paid' is not set,
// Redirect to A FULL URL AS PER THE MANUAL
header("Location: http://www.mysite.com/paidonly.php");
exit;
}
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I think it was insterted with a query. Im not exactly sure, i used an extremely stripped login code, and modified it to how i wanted it to work.
Again, i dont know anything about sessions, so if this isnt them being set, i have no idea what to look for, and im sorry for a useless post. :/
INSERT INTO loginphp
(Uname, Email, Pword) VALUES('$ADMINUNAME', '$ADMINEMAIL', '$ADMINPWORD')
Again, i dont know anything about sessions, so if this isnt them being set, i have no idea what to look for, and im sorry for a useless post. :/
INSERT INTO loginphp
(Uname, Email, Pword) VALUES('$ADMINUNAME', '$ADMINEMAIL', '$ADMINPWORD')
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Ok, lets simplify things a bit...
Usually, a login process consists of validation, authentication and/or access control. When a user is validated, session vars are set to include basic information about the user...
This is an extremely stripped down method demonstration, but it should give the basic logic of what you want to do.
Usually, a login process consists of validation, authentication and/or access control. When a user is validated, session vars are set to include basic information about the user...
Code: Select all
<?php
session_start();
$user_validated = false;
// after the login checking and validation...
// maybe during the data fetch from the database
while ($row = mysql_fetch_array($result))
{
$user_validated = true;
$_SESSION['username'] = $row['username'];
$_SESSION['userlevel'] = $row['userlevel';
// This would be a great place to handle the paid var
$_SESSION['userpaid'] = $row['userpaid'];
}
if ($user_validated)
{
header("Location: http://www.mysite.com/goodlogin.php");
exit;
}
else
{
header("Location: http://www.mysite.com/badlogin.php");
exit;
}
?>
Last edited by RobertGonzalez on Sun Aug 06, 2006 11:55 pm, edited 1 time in total.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA