Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,835 members, 8,003,970 topics. Date: Saturday, 16 November 2024 at 03:22 AM

Redirect User To Different Pages On First Time Login - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Redirect User To Different Pages On First Time Login (1309 Views)

How To Redirect A Website Based On Screen Resolution / I Need A Help To Write A Simple Login Form Using Vb.net / Any Netbeans User To Help Me Out Of This Hook. (2) (3) (4)

(1) (Reply)

Redirect User To Different Pages On First Time Login by danielatunrase(m): 2:16am On Aug 30, 2012
Hi,
I am using dreamweaver to develop a member area for a client's website. I need to check from the database if the person is logging on for the first time and redirect accordingly and then update the database so that it recognizes the person has logged on before. I am using php/mysql and have created am integer field called firsttime in my database and created my login page. I named the page the login goes to as redirect.php and have a code generated by dreamweaver to protect the page from unauthorized access. I am very new to this but understand the basics of what i want done. If someone could help me flesh it out I'd appreciate it.
1. Select the database
2. select firsttime from the database table where the username is still the session variable (Dreamweaver uses this $_SESSION['MM_Username'])
3. store the result of the query in a variable liek the result in the example below
4. check if the result is 1 (for an old user) and redirects to one.php or if the result is 0 (for a new user) and redirects to zero.php at the same time updating the firsttime field to 1 in this case.

Thats about it. I found this example in my search online but i don't know how to customize it to fit my needs. Will really appreciate the help
Regards.


<?php

$checkvisits = "SELECT firsttime FROM churchushers WHERE user=$user";
$result = mysql_query($checkvisits);
if($result <= "1"wink{
header("Location: first.php"wink;
} else {
?>
Re: Redirect User To Different Pages On First Time Login by dellnet: 10:56am On Aug 30, 2012
mysql_query()will return success if the query is valid. Here is something:

$checkvisits = "SELECT firsttime FROM churchushers WHERE user=$user";
$res = mysql_query($checkvisits);
if ($res) //i.e. if the query returns success, fetch the result
{
$crude = mysql_fetch_row($res);
if($crude[0] == 1) //in this case it is "an old user"
{
//go ahead and redirect appropriately
//header("Location:blah_blah" );

}
else if ($crude[0] == 0) //in this case "new user"
{
$sqlupdate ="UPDATE churchusers SET firsttime = 1 WHERE user=".$user;
mysql_query($sqlupdate ) ;
//redirect appropriately
//header("Location:blah_blah" ) ;
}
}

The code does not check for errors for example if the query exist or is valid. For more info on php mysql functions visit http://php.net/manual/en/ref.mysql.php
Re: Redirect User To Different Pages On First Time Login by bakenda(m): 1:42pm On Aug 30, 2012
@OP, You seems to be on track.

Just to add, you need not write a separate query
to select the firsttime column, select it
in the query for validating users at login.

Make the firsttime column 0 by default.

Then proceed as explained in the above post.

Let's know how it goes.

(1) (Reply)

Pls Programmers In PHP And MYSQL Help Out On This / How To Prevent A Website From Being Hacked / Teacher Gave Me Punishment To Write 5000 Times The Following Line

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.