Forum Moderators: coopster

Message Too Old, No Replies

redirect maybe?

         

chapm4

7:16 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



Hi everyone,
New to the world of PHP and happened upon the site, may we have many happy memories together.

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.

vevs

7:36 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



you can redirect users using both PHP or JavaScript

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

chapm4

7:46 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



forgive my ignorance...

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.

vevs

10:40 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



I used companyA.php because you used it too. Do you have different page for each company?
I assume that in your MySQL database each company has it's own ID. The best way to do this is to redirect to a single php page and to pass company ID to id.
company.php?id=1

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

chapm4

3:02 pm on Feb 20, 2006 (gmt 0)

10+ Year Member



Can we keep this going a bit more.

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>';
}