Jul 25, 2008

Problem With Headers - setcookie errors

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Problem With Headers - setcookie errors

HmmZ
I'm having troubles with my authentication function, if the the users uses wrong login info, it works like a charm, but it gives me errors when i set the cookies, so help would be appreciated...

CODE
Function auth(){
$user=$_POST['username'];
$pass=$_POST['password'];
$qry="SELECT id from Solarity where username='$user' and password='$pass'";
$result=mysql_query($qry) or die("A problem occured during authentication process");
$rows=mysql_num_rows($result);
if($rows<=0){
print "<font class=\"content\">Wrong username and/or password<br>";
print "$user | $pass<br>";
print "<a href=\"javascript:history.go(-1)\"><b>Go Back</b></a></font>";
exit;
}
elseif($rows=1) {
setcookie("logged", "TRUE", time()+(900*1));
setcookie("username", "$user");
print "<font class=\"content\">Successfully logged in $user<br>";
print "<a href=\"index.php?fid=area\">Continue to Admin Area</a></font>";
}}


By the way, the headers errors kicked in when i inserted the font classes (to give a cleaner display >.> . I hope it isn't the problem..

 

 

 


Reply

truefusion
I'd have to say it's because you used the "elseif" function, but i could be wrong. It might work if you change it to just "else".

Reply

TimothyA
cookies are evil! use sessions smile.gif

and as for the code...you got it reversed....

use the if {} else {} magic dude! biggrin.gif

the if statement ought to be the "correct user/pass" routine and else should be if the user/pass is wrong... but that's just my 50 dollars.


If you're really desperate you can use my code as a guide wink.gif
CODE

  if (mysql_num_rows($result) == 1) {
     // the user id and password match,
     // set the session
     $_SESSION['user_is_logged_in'] = true;

     // after login we move to the main page
  echo '<meta http-equiv="refresh" content="1;url=/members/index.php">';
     echo "<div align=\"center\">Welcome back $userId, you are being directed to the members page.</div>";
     exit;
  } else {
     $errorMessage = 'Sorry, wrong user id / password';
  }


 

 

 


Reply

HmmZ
My god, I am soooooo smart >.>

I first had the full script in index.php, after seeing the lots kb it would gonna have eventually (function bases structure) i decided to make a main.php and include it in my index.php...after that...i decided to put header stuff and footer stuff in separate files and include it aswell (leaving 85bytes on index.php

You can guess...the output started at "header.php:8" to be more precise, I had the following:

index.php
CODE
<?php
include("config.php");
include("header.php");
require_once("main.php");
include("footer.php");
?>


main.php
CODE

<?php
session_start;
include("config.php");


as you can see, while the header include in index.php comes BEFORE the include of main.php, it already has send headers, so the only thing i actually had to do was take off the header.php include in index.php and do the include in main.php

index.php
CODE
<?php
include("config.php");
require_once("main.php");
include("footer.php");
?>


main.php
CODE
<?php
session_start;
include("header.php");
include("config.php");


and that works, no header errors anymore biggrin.gif

I hope that all made any sense, lotsa followups per line laugh.gif

Reply

beeseven
A little something I noticed: You have "elseif($rows=1)," but it should be "elseif($rows==1)," because the first would be like "if the value 1 is assigned to $rows" as opposed to "if the value of $rows is 1."

Reply

HmmZ
Thanks for the additional comment beeseven happy.gif , ill keep it in mind for next time smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : problem, headers, setcookie, errors

  1. Fopen Errors :(
    grrr, i'm angry :( (6)
  2. New Found Php Coding Errors
    I always thought these worked, but suddenly they no longer do?! (5)
    Hi i'm dan from new zealand, right next to my home land australia. I have been writing php
    scripts for two years now and just recently none of them have been working. Please help me out as
    best as you can, i'm sure it is only something simple. CODE ----------------Form
    1-------------------------- <?php // ---- Customized form script for the HBRC---------------
    // Receiving variables ----------------------------------- @$fn =
    addslashes($_POST['fn']); @$ln =
    addslashes($_POST['ln']); @....
  3. Header Redirect Errors
    (5)
    Hi, I am using the header function to redirect after the processing of the form. I have to specify
    a internal link using '#link'. This works in Firefox and opera. But in Internet Explorer
    internal linking when done from a redirect is not working for somewhat reasons. e.g.
    header("Location: http://www.example.com/index.php#link"); this works in Firefox and Opera but
    not in Internet Explorer . IE just accepts 'http://www.example.com/index.php' instead of
    http://www.example.com/index.php#link Please help me if you know anything about this. Well ther....
  4. Script Not Working :s
    mysql errors (5)
    process_login.php: Process the login. $host = "localhost";// the host that u are connecting
    $username = "root";// user name $password = ""; // passworld $basedatos =
    "forum"; //Dont change this1. $db = mysql_connect($host, $username, $password);
    mysql_select_db($basedatos, $db); $user= $_REQUEST ; $pass=
    md5($_REQUEST ); $query1= "SELECT * FROM smf_members WHERE
    memberName='$user'"; $mkquery= mysql_query($query1,$db); $row1=
    mysql_fetch_assoc($mkqu....
  5. A Answer Of "headers Already Sent"
    (11)
    I install a php script on my trap 17 host. Everything is perfect before I test the script. When I
    login, it suddenly displays as following: QUOTE Warning: Cannot modify header information -
    headers already sent by (output started at /home/whistle/public_html/center/counter/config.php3:20)
    in /home/whistle/public_html/center/counter/Change.php3 on line 20 I watch the config.php3,
    nothing is incorrect. Then I look at the Change.php3, there is nothing wrong. Then I try to find the
    history topics in the Trap17. It is interesting, I am not the only one in the same tr....
  6. Getting Errors On A Script
    need to know what im doing wrong (3)
    ok please help me!! im trying to get this tournamt/leage ladder script working, its with php
    but i think i put all the files in the right palces but i keep getting this error .... CODE
    Warning: main(modules/NukeLadder/admin/index.php): failed to open stream: No
    such file or directory in /home/berkolli/public_html/DjLuki/admin/case/case.php on line 77
    Warning: main(modules/NukeLadder/admin/index.php): failed to open stream: No
    such file or directory in /home/berkolli/public_html/DjLuki/admin/case/case.php on line 77 W....
  7. Getting Rid Of Errors
    (4)
    Hi Is it ok to use error-reporting(0) locally in a snippet of code that spits an undefined variable
    error? I found that fix and was wondering what does everybody do about error messages that keep
    poping up. Thanks Patrick....
  8. Mysql Errors
    cant find whats wrong :( (3)
    I am working on my guestbook, better to say I am transfuring it from old to new site, but I got some
    errors now I did not had at my old hoster and I cannot figure out whats wrong: CODE
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
    /home/pbrugge/public_html/guest.php on line 104 Warning: mysql_fetch_array():
    supplied argument is not a valid MySQL result resource in /home/pbrugge/public_html/guest.php on
    line 110 This is the complete relevant code perhaps I overlooked something but I keep ove....

    1. Looking for problem, headers, setcookie, errors

Searching Video's for problem, headers, setcookie, errors
advertisement



Problem With Headers - setcookie errors



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE