Forum Moderators: coopster
Let me explain the site first and then the issue I need help with.
The site sells customized baseball bats. The old site used php for the customer to log in (through cookies). The user was then sent to a page with their companies bat at the top and an order form. When the order form was submitted it sent an email to the manufacturer with the form information.
We are converting this to a database currently(mysql)
The issue: I have currently a pop up for the user to log in which is validated against the database. Currently they get a page saying they are validated. What I need to do is like the old system, if they validate as companyA they should go to companyA.php
The problem is, I don't really have a clue how to do this. I looked a bit at some code for redirect but I am not sure that fits in this case. Can someone help me? We've got about 20 customers(companies) in the database.
PHP
<?
header ("Location [yoursite.com...]
?>
JavaScript
<script language="JavaScript">
window.location.href = 'http://www.yoursite.com/companyA.php';
</script>
let me know if this answers your question
So if username is companyA then I want to set a variable and use that variable in the redirect? Can you give me an example of this? And I would like to use PHP.
One other question tacked onto this. In my login table I have a field called logged which is a date format. I want this to update when companyA logs in to be able to look at last logins, but not sure how to update this.
Thanks a lot for your help.
and instead of
header ("Location [yoursite.com...]
you will use
header ("Location [yoursite.com...]
where 1 is the company ID you want to redirect to
using mysql SELECT query and that ID the company.php script get company 1 details from the DB and shows them on the page. So if you open company.php?id=2 that mysql query will get details about company 2 and will show its details.
If you just want to show last login, you can have an UPDATE query when user logins. But if you want to record all logins you need new table where to insert new record on every login.
Update query could be like this
UPDATE tablename SET loginfield=now() WHERE companyID=1
I understand the redirect. Thanks very much on the help for that.....My code looks like this after connecting to the database. (below) I do have a company_Id field in the database and so in theory if this is company1 logging in then they should be redirrected to company1.php, if its company_id 2 then company2.php
How is this done?
// Formulate the query
$sql = "SELECT * FROM login WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num!= 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if (! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
echo '<P>You are authorized!</P>';
}