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
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
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
Share on other sites

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

That really [i]is[/i] just personal preference. Curly braces are only required around complex variables. eg arrays.
Link to comment
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.