Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect based on database field (URL) 1

Status
Not open for further replies.

rninja

Technical User
Apr 11, 2001
381
US
Is there any way on php to get a url out of mysql and redirect to it? I have a login script that works properly out of the mysql database and validates and starts a session. The problem is that my tables include a "url" field. The user logs in with username and password, then the user is supposed to be redirected via the address in the database.

I haven't found a way to do this. So far I've seen the header("Location: /url "); method, but it simply uses a url imputted to the script. It's not dynamic.

I also tried plugging the url into a variable, with no luck.

I'd appreciate any help with this! Rninja

smlogo.gif

 
This should do it:
Code:
<?php
//connect to the database
//get the uri from the database and validate the user at the same time
$result = mysql_query(&quot;SELECT uri_column FROM users WHERE username='&quot;.$_POST['username'].&quot;' AND password='&quot;.$_POST['password'].&quot;'&quot;);
if (mysql_num_rows($result) > 0)
{
    // do stuff that you do to users that logged in
    list($uri) = mysql_fetch_row($result);
    header(&quot;Location: $uri&quot;);
}
else
{
    // the user wasn't able to log in
}
?>
To use it, just create a form with a username and a password field. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top