Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Redirect

Featured Replies

Hey guys,

 

I have setup my database, table and register form. When I log-in everything is fine...however the page stays on login.php?op=login and doesn't redirect to members.php

 

I have included my code below to see if you can spot any errors.

 

Cheers for your help!

 

Josh ;)

 

		<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
 {
 die("You need to provide a username and password.");
 }

// Create query
$q = "SELECT * FROM `dbUsers` "
 ."WHERE `username`='".$_POST["username"]."' "
 ."AND `password`=PASSWORD('".$_POST["password"]."') "
 ."LIMIT 1";
// Run query
$r = mysql_query($q);

if ( $obj = @mysql_fetch_object($r) )
 {
 // Login good, create session variables
 $_SESSION["valid_id"] = $obj->id;
 $_SESSION["valid_user"] = $_POST["username"];
 $_SESSION["valid_time"] = time();

 // Redirect to member page
 Header("Location: members.php");
 }
else
 {
 // Login not successful
 die("Sorry, could not log you in. Wrong login information.");
 }
}
else
{
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>

Using the header(...) function makes a change to the HTTP headers (duh!). But in order for this to happen, no content must be been written to the HTTP body of the response before header() is invoked. Therefore you need to ensure nothing is written to the body - usually some extra whitespace before a <?php or in some included file is the reason for the error. Ensure that all <?php are right at the beginning of the file with no whitespace, and similarly for any included PHP files with the ?> which needs to be right at the very end (no trailing whitespace).

Using the header(...) function makes a change to the HTTP headers (duh!). But in order for this to happen, no content must be been written to the HTTP body of the response before header() is invoked. Therefore you need to ensure nothing is written to the body - usually some extra whitespace before a <?php or in some included file is the reason for the error. Ensure that all <?php are right at the beginning of the file with no whitespace, and similarly for any included PHP files with the ?> which needs to be right at the very end (no trailing whitespace).

 

Also close your session start at the beginning

 

<?php

session_start();?>

<?php

// dBase file

include "dbConfig.php";

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.