Jump to content

Recommended Posts

<?php
//successful login
$url = $rows['url']; //url got from MySQL table
header("Location: $url");
?>

 

To actually use header(), the script must have not send any output (html, js, css, php print, cookie, whatever) to the browser, or you'll get an error. To make for that problem, you can use output buffering or alternatively, meta refresh (deprecated) or javascript (not recommended).

Link to comment
https://forums.phpfreaks.com/topic/234554-log-in-help/#findComment-1205414
Share on other sites

<?php
//successful login
$url = $rows['url']; //url got from MySQL table
header("Location: $url");
?>

 

To actually use header(), the script must have not send any output (html, js, css, php print, cookie, whatever) to the browser, or you'll get an error. To make for that problem, you can use output buffering or alternatively, meta refresh (deprecated) or javascript (not recommended).

what does $rows = ???

Link to comment
https://forums.phpfreaks.com/topic/234554-log-in-help/#findComment-1205419
Share on other sites

I'll elaborate my answer. As you mentioned "URL stored in a table", I thought you had the basic idea.

 

A simple login script

<?php
//username and password from POST data. Clean username for use in query and hash password.
$username = mysql_real_escape_string($_POST['username']);
$password = sha1($_POST['password']);

//make a query to the 'users' table to see if a user with the correct username/password combination exists.
$results = mysql_query("SELECT id, url FROM users WHERE username='$username' AND password='$password' LIMIT 1");
//if query returns 1 row, then the provided username/password are correct.
if (mysql_num_rows($results)) {
     //fetch data into an associative array.
     $values = mysql_fetch_assoc($results);

     //create a session variable to hold the user's id.
     $_SESSION['user'] = $values['id'];
     
     //the url stored in the MySQL table.
     $url = $values['url'];

     //redirect the user to the url.
     header("Location: $url");
}
?>

 

The script doesn't do any error handling, validation or whatever. It's just bare-bones to give you the idea.

Link to comment
https://forums.phpfreaks.com/topic/234554-log-in-help/#findComment-1205422
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.