Jump to content

redirecting


chriscloyd

Recommended Posts

okay i made my login script and for whatever reason its not returning to any page

heres my code

[code]
<?php
error_reporting(E_ALL);
ini_set('log_errors','1');
ini_set('display_errors','0');
session_start();
include("config.php");
//login
$username = $_POST['username'];
$password = md5($_POST['password']);
$timendate = date("n/j/Y g:i:s A");
$get_user = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$numusers = mysql_num_rows($get_user) or die(mysql_error());
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ip = $_SERVER['REMOTE_ADDR'];
$description = 'Login';
if ($numusers > 0) {
$user = mysql_fetch_array($get_user) or die(mysql_error());
if ($username == $user['username']) {
//check_passwords now
if ($password == $user['password']) {
$_SESSION['ccloyd'] == $username;
$status = 'Success';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../?page=home");
} else {
$error = 'Wrong Login Info.';
$status = 'Failed';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../?false=$error");
}
} else {
$error = 'Wrong Login Info.';
$status = 'Failed';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../?false=$error");
}
} else {
$error = 'Wrong Login Info.';
$status = 'Failed';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../?false=$error");
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32486-redirecting/
Share on other sites

[CODE]
<?php
session_start();
include("config.php");
error_reporting(E_ALL);
ini_set('log_errors','1');
ini_set('display_errors','0');
//login
$username = $_POST['username'];
$password = md5($_POST['password']);
$timendate = date("n/j/Y g:i:s A");
if (isset($_POST['username'])){
$get_user = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$numusers = mysql_num_rows($get_user) or die(mysql_error());
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ip = $_SERVER['REMOTE_ADDR'];
$description = 'Login';
if ($numusers > 0) {
$user = mysql_fetch_array($get_user) or die(mysql_error());
if ($username == $user['username']) {
//check_passwords now
if ($password == $user['password']) {
$_SESSION['ccloyd'] == $username;
$status = 'Success';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../index.php?page=home");
} else {
$error = 'Wrong Login Info.';
$status = 'Failed';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../index.php?false=$error");
}
} else {
$error = 'Wrong Login Info.';
$status = 'Failed';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../index.php?false=$error");
}
} else {
$error = 'Wrong Login Info.';
$status = 'Failed';
mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error());
header("Location: ../index.php?false=$error");
}
}
?>
[/CODE]


i just updated it and its still not redirecting
Link to comment
https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-150934
Share on other sites

and just some proper php coding stuff that you should fix up.

i personally dont like seeing variables used inside of strings unless surrounded by curly brackets...

either of these is good:
[code=php:0]header("Location: ../index.php?false={$error}");[/code]
or:
[code=php:0]header("Location: ../index.php?false=".$error);[/code]

but yeh change the ../ to the EXACT url.
Link to comment
https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-150982
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.