Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[SOLVED] PHP Login Script problem

login

  • Please log in to reply
2 replies to this topic

#1 Thevenin

Thevenin

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 66 posts

Posted 17 August 2012 - 06:08 AM

Hi all, I am creating an administration panel; this is the first time for me and I have some problems.
In the init.inc.php file I have this code below.

<?php

session_start();

include("login.inc.php");

$ext = explode("/", $_SERVER['SCRIPT_NAME']);
$ext = $ext[count($ext)-1];
$page_name = substr($ext, 0, -4);
echo $page_name;
echo "<br />";

//$page_name = substr(end(explode("/", $_SERVER['SCRIPT_NAME'])), 0, -4); // init.inc
$required = array("admin", "logout");
//print_r($required);

if(isset($SESSION['username']) === false) {
if((isset($_COOKIE['username'], $_COOKIE['password'])) && (validating_infos($_COOKIE['username'], $_COOKIE['password']))) {
$_SESSION['username'] = $_COOKIE['username'];
header("Location: ../admin/admin.php");
exit();
} else if(in_array($page_name, $required)) { // THE PROBLEM IS THIS CONTROL
header("Location: ../content/login.php"); // THE PROBLEM IS THIS CONTROL
exit(); // THE PROBLEM IS THIS CONTROL
}
} else if(in_array($page_name, $required) === false){
header("Location: ../admin/admin.php");
}
?>

I use an array of all the pages that request a login to be viewed. So the user has to be logged in to see them, but it doesn't work.
When I try to login, I will be redirected back to the login page. If I remove the pages from the required array it works, but for all people!! Any hint?
  • 0

#2 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 17 August 2012 - 12:15 PM

I think ... the issue is because you already have something echo to the page:

echo $page_name;
echo "<br />";

Check out this link: http://php.net/manua...tion.header.php

someone suggests:

<?php

function Redirect($Str_Location, $Bln_Replace = 1, $Int_HRC = NULL)
{
if(!
headers_sent())
{
header('location: ' . urldecode($Str_Location), $Bln_Replace, $Int_HRC);
exit;
}

exit(
'<meta http-equiv="refresh" content="0; url=' . urldecode($Str_Location) . '"/>'); # | exit('<script>document.location.href=' . urldecode($Str_Location) . ';</script>');
return;
}

  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.


#3 Thevenin

Thevenin

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 66 posts

Posted 18 August 2012 - 12:01 AM

Hi and thank you for the answer. The problem wasn't in those lines of code, but in another file. I commented some lines to test and forgot to commented out.
So the login couldn't validate the username & password because it couldn't set them. Solved now.
  • 0





Also tagged with one or more of these keywords: login

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download