+ Reply to Thread
Results 1 to 7 of 7

Thread: help with php script

  1. #1
    samurai1993's Avatar
    samurai1993 is offline x10Hosting Member samurai1993 is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    chile
    Posts
    26

    help with php script

    I am programming a simple forum script (yes, I know, there is a lot of open source scripts in the web) and I started with the users system (registry of users and login)

    For security, I am using sha256 to encript the password, in two pass:
    1) In one file I have the Salt text, encripted in md5... for example:

    Code:
    $salt = hash(md5, 'starwars')
    2) In the Users Registry script I encript the password:
    Code:
    $password = hash(sha256, $salt . $HTTP_POST_VARS["password"]
    I think you saw that I "double encript" the Salt text (the variable $salt is saved in a configuration file, and I call the file using require() )

    3) All works well, the user's info is saved in the mysql, etc

    4) Now I am going to try the login script...

    5) The login script consist in a html file:
    Code:
          <FORM ACTION="1.php" METHOD="post">
          Nick : <INPUT TYPE="text" NAME="nick" SIZE="20" MAXLENGTH="20">
          <BR>
          Password: <INPUT TYPE="password" NAME="password" SIZE="28" MAXLENGTH="20">
          <BR>
          <INPUT TYPE="submit" CLASS="boton" VALUE="Ingresar">
          </FORM>
    6) this file redirects me to a php script that create "cookies" with the required info:

    Code:
    <?php
          setcookie("nick",$HTTP_POST_VARS["nick"],time()+7776000);
          setcookie("pass",hash('sha256', '$salt . $HTTP_POST_VARS["password"]'),time()+7776000);
    ?> 
    
          <SCRIPT LANGUAGE="javascript">
          location.href = "2.php";
          </SCRIPT>
    this script encript the password :lockd:

    7) the script redirects me to a second file with the function of validate the cookies info:

    Code:
    <?php
           
          require(imaginary_config_file.php');
    
          function quitar($mensaje)
          {
          $mensaje = str_replace("<","&lt;",$mensaje);
          $mensaje = str_replace(">","&gt;",$mensaje);
          $mensaje = str_replace("\'","'",$mensaje);
          $mensaje = str_replace('\"',"&quot;",$mensaje);
          $mensaje = str_replace("\\\\","\\",$mensaje);
          return $mensaje;
          }
          
          if(trim($HTTP_COOKIE_VARS["nick"]) != "" && trim($HTTP_COOKIE_VARS["pass"]) != "")
          {
          $passN = quitar($HTTP_COOKIE_VARS["pass"]);      
          $nickN = quitar($HTTP_COOKIE_VARS["nick"]);      
          $result = mysql_query("SELECT password FROM usuarios WHERE nick='$nickN'");
          if($row = mysql_fetch_array($result))
          {
          if($row["password"] == $passN)
          {
          //90 dias dura la cookie
          setcookie("usNick",$nickN,time()+7776000);
          setcookie("usPass",$passN,time()+7776000);
          ?>
          Ingreso exitoso, ahora sera dirigido a la pagina principal.
    
          <?
          }
          else
          {
          echo "Password incorrecto";
          }
          }
          else
          {
          echo "Usuario no existente en la base de datos";
          }
          mysql_free_result($result);
          }
          else
          {
          echo "Debe especificar un nick y password";
          }
          mysql_close();
          ?>
    I think is a really secure metod with offers security for me and the users... well, here is where I get the error:

    Code:
    Warning: Cannot modify header information - headers already sent by (output started at /home/samurais/public_html/pruebas/ingresar_user2.php:1) in ------------/2.php on line 25
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/samurais/public_html/pruebas/ingresar_user2.php:1) in -----------/2.php on line 26
          Ingreso exitoso, ahora sera dirigido a la pagina principal.
    9) Note that this is not my first attempt for made this script work, I tested three differents metods, with the same result

    Please help me!!!

    p.d: All the file names and other things that represents a security issue for me and x10hosting were changed

    p.d 2: sorry for my english, I only have 13 years xD

    p.d 3: I tested only the script that creates the first cookies and I don't have any problem, I used the firefox extension Web Developer to saw the cookies and all is in his place
    Last edited by samurai1993; 06-15-2007 at 08:46 PM.


    :laugh: SOMOS LA HINCHADA DEL PUEBLO:laugh:
    :cool: SANTIAGO WANDERERS DE VALPARAISO!!!!:cool:

  2. #2
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: help with php script

    You're getting that error because something is being sent to the browser (output of some sort) before header() is called, (or setcookie(), session_start(), whatever - anything that deals with HTTP headers). That cannot happen.

    "output started at /home/samurais/public_html/pruebas/ingresar_user2.php:1"

    'ingresar_user2.php' is sending output from line 1. Check that line and eliminate the output and it should work fine.

    I'm not sure how strong your knowledge is of PHP, so let me know if I need to explain more.
    Last edited by Bryon; 06-15-2007 at 11:21 PM.

  3. #3
    samurai1993's Avatar
    samurai1993 is offline x10Hosting Member samurai1993 is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    chile
    Posts
    26

    Re: help with php script

    my php knowledge is very basic, the scripts that I put here are all based in tutorials (obviously, modificated by me in a little number of aspects... the only thing that I wrote is the encript script)

    please explain me, I will aprecciate it :happysad:


    :laugh: SOMOS LA HINCHADA DEL PUEBLO:laugh:
    :cool: SANTIAGO WANDERERS DE VALPARAISO!!!!:cool:

  4. #4
    Zenax's Avatar
    Zenax is offline Lord Of The Keys Zenax is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    The Brilliant United Kingdom
    Posts
    1,339

    Re: help with php script

    Basically what Bryon is saying is that there is something on line one of ingresar_user2.php script that is outputting a value. This line either has to be removed or changed so that it stops outputting before headers are sent.

    Now when I have come across something like this it tends to be that there is a space before it or something and it causes an error. Normally removing all spaces from scripts might cure it. My knowledge is also very limited at PHP but thats my guess at your problem.
    Regards,
    Zenax

  5. #5
    samurai1993's Avatar
    samurai1993 is offline x10Hosting Member samurai1993 is an unknown quantity at this point
    Join Date
    Sep 2006
    Location
    chile
    Posts
    26

    Re: help with php script

    thanks Bryon and Zenax!!!
    I totally forgotten that setcookie() can't be used if there is a white space or something before <php?
    what a stupid error!!!! :pat:


    :laugh: SOMOS LA HINCHADA DEL PUEBLO:laugh:
    :cool: SANTIAGO WANDERERS DE VALPARAISO!!!!:cool:

  6. #6
    Zenax's Avatar
    Zenax is offline Lord Of The Keys Zenax is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    The Brilliant United Kingdom
    Posts
    1,339

    Re: help with php script

    absolutly no problem at all. just let us know if you have any more problems with your scripts and im sure we could help!
    Regards,
    Zenax

  7. #7
    Chris Z's Avatar
    Chris Z is offline x10 Spammer Chris Z is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Alabama, USA
    Posts
    2,802

    Re: help with php script

    I guess this is all solved or whatever, but have you tried using ob_start(), which stands for OutputBuffer?
    Last edited by Chris Z; 06-16-2007 at 08:10 PM.
    -Chris Z
    Retired Account Manager


+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  3. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  4. Need help with PHP script
    By cyberxzt in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 01-06-2007, 01:43 PM
  5. Remove Documentation PHP Script
    By amr1991 in forum Scripts & 3rd Party Apps
    Replies: 5
    Last Post: 12-09-2006, 11:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers