Jump to content

chris.smith

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Posts posted by chris.smith

  1. die("Incorrect Username or Password, please check your credentials!");

     

    ^^^ The first die() statement actually means that the field(s) were left blank and the code should display that message and then redisplay the form. The message should be corrected.

     

    Also, by using die() for the above and using die() when the query does find a matching row, you are preventing the form from being redisplayed so that the user could enter the correct information.

     

    Those are true and I guess these are the consequences of writing a script in 20 seconds :P

     

    Cheers

  2. Hi guys. Really basic question here. I have created a mailto PHP script, which is not working when I try it out. My website is currently offline and not running through the webserver. Does the website need to be online for the PHP script to work?

     

    Many thanks

     

    I'm assuming that the script exists on your website or uses the mail server on your website.

    In the first case yes your website needs to be live so that you can access the script.

    In the second case your website can be down but your mail server needs to be live.

     

    Cheers.

  3. Hmmmm...still echoing incorrect login credentials...

     

    Sorry didn't get a chance to debug the code. I'm guessing that this should solve the problem.

    Use this code:

    <?php
    session_start();
    require_once('dbConfig.php');
    
    if($_GET['op'] == 'login') {
    if (empty($_POST["username"]) || empty($_POST["password"])) {
    	die("Incorrect Username or Password, please check your credentials!");
      	} else {
    	if(get_magic_quotes_gpc()) {
    		$_POST['username'] = stripslashes($_POST['username']);
    		$_POST['password'] = stripslashes($_POST['password']);
    	}
    
    	$q = "SELECT * FROM `access` WHERE `username`='" . mysql_real_escape_string($_POST["username"]) . "' AND `password`=PASSWORD('" . $_POST["password"] . "') LIMIT 1;";
    	$r = mysql_query($q);
    	$num = mysql_num_rows($r);
    
    	if($num == 0) {
    		die("Incorrect Username or Password, please check your credentials!");
    	} else {
    		$row = mysql_fetch_row($r);
    		$_SESSION["valid_id"] = $row[0];
    		$_SESSION["valid_user"] = $_POST["username"];
    		$_SESSION["valid_time"] = time();
    		Header("Location: main_interface.php");
    	}
    }
    } else {
      echo "<form action=\"?op=login\" method=\"POST\">";
      echo "Username: <input name=\"username\" size=\"15\"><br />";
      echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
      echo "<input type=\"submit\" value=\"Login\">";
      echo "</form>";
    }
    ?>
    

     

    Cheers

  4. Hi all,

     

    Example scenario:

     

    I have a page (let's call it pageone.php) which contains a form.  On submit the form calls a php script (let's call it script.php) which includes an echo statement if a "IF query" is false. 

     

    Problem is, the echo appears at the url www.mysite.com/script.php - how do i display the echo (or an alternative to it) back on /pageone.php - and is it possible to customize where on the page this message is displayed? (i.e. after the relevant part of the form the message relates to).

     

    I've done a little reading into print and echo statements, but if someone could link me or give me some pseudo code for the form and then the script so i can see how script prints / echos / 'whatever's' to the form i'd really appreciate it.

     

    Cheers all,

     

    Tom.

     

    It would be much easier to integrate the form into pageone.php and if needed use require or require_once to include script.php.

    You could identify an input by a $_GET key, as in:

    http://local/pageone.php?form=submit

     

    Cheers.

  5. Chris, thank you for the reply! I went ahead and made the suggested changes but now it is echoing that I entered incorrect login information, even though it is correct....    :shrug:

     

    My fault sorry.

    Change:

    !empty($_POST["username"]) || !empty($_POST["password"])

     

    To:

    empty($_POST["username"]) || empty($_POST["password"])

     

    Cheers

  6. My main focus is creating websites. I know CSS and html and I know its time to learn a scripting language.  It would be nice to have both a general purpose programming language and web scripting language under my belt. PHP No? Two birds one stone so to speak.  So my question is would it be a good idea to use PHP for general purpose programming or just take the time to learn python also?

     

    If your application needs to communicate with the web then yes, php can be adjusted to just about every web situation.

    Moreover Facebook recently released a tool called HipHop that can convert your php scripts into high-speed c++ binaries.

  7. Hello,

     

    i have a user entering dates in the format

     

    DD-MM-YYYY --> 11-12-02

     

    when i try to sort by DESC [nearest date first] i am getting sort problems for example i'll get this..

     

    11-12-02

    12-07-02

    13-08-02

     

    whats the best way to sort this to get the dates correct?

     

    What datatype do you use in your database?

     

    Cheers.

  8. Hi,

     

    I am using the include function to link my header and menu up to my files.

     

    My folder structure is:

     

    WWW Folder

        -head.html

        -menu.html

        -homepage.php

    Images Folder

    Blog Folder

        -index.php

     

    The head.html and menu.html have links to images kept within the images folder.

    homepage.php and index.php both have include functions to include the menu and header thus including the images.

     

    homepage.php works fine the images show up however blog.php links to the head and menu but does not show up the images.

     

    my include function for index.php is:

    <?php

    include ("..\menu.html");

    ?>

     

    I have attached a print screen of what the index.php looks like, its obvious that its picking up the head and menu as its showing the image names but not showing the images.

     

    Can anybody help it's really confusing me? Thanks :)

     

    Make a menu2.html file that adds "..\" in front of the image paths and include that one in index.php.

  9. Okay, I went ahead and completely changed the coding for the login, but it is still returning a blank page. I have attached code for reference.

     

    Login Page

    <?php
    session_start();
      // dBase file
    include "dbConfig.php";
    
    if ($_GET["op"] == "login")
      {
      if (!$_POST["username"] || !$_POST["password"])
      	{
      	die("Incorrect Username or Password, please check your credentials!");
      	}
      
      // Create query
      $q = "SELECT * FROM `access` "
      	."WHERE `username`='".$_POST["username"]."' "
      	."AND `password`=PASSWORD('".$_POST["password"]."') "
      	."LIMIT 1";
      // Run query
      $r = mysql_query($q);
    
      if ( $obj = @mysql_fetch_object($r) )
      	{
      	// Login successful, create session variables
      	$_SESSION["valid_id"] = $obj->id;
      	$_SESSION["valid_user"] = $_POST["username"];
      	$_SESSION["valid_time"] = time();
    
      	// Redirect to main database page
      	Header("Location: main_interface.php");
      	}
      else
      	{
      	// Login not successful
      	die("Unable to login, please verify your information.");
      	}
      }
    else
      {
    //If all went right the web form appears and users can log in
      echo "<form action=\"?op=login\" method=\"POST\">";
      echo "Username: <input name=\"username\" size=\"15\"><br />";
      echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
      echo "<input type=\"submit\" value=\"Login\">";
      echo "</form>";
      }
    ?>
    

     

    This is the first code on 'main_interface.php'

    session_start();
    if (!$_SESSION["valid_user"])
    {
    // User not logged in, redirect to login page
    header("Location: interface_login.php");
    }
    

     

    Try this code:

     

    <?php
    session_start();
    require_once('dbConfig.php');
    
    if($_GET['op'] == 'login') {
    if (!empty($_POST["username"]) || !empty($_POST["password"])) {
    	die("Incorrect Username or Password, please check your credentials!");
      	} else {
    	if(get_magic_quotes_gpc()) {
    		$_POST['username'] = stripslashes($_POST['username']);
    		$_POST['password'] = stripslashes($_POST['password']);
    	}
    
    	$q = "SELECT * FROM `access` WHERE `username`='" . mysql_real_escape_string($_POST["username"]) . "' AND `password`=PASSWORD('" . mysql_real_escape_string($_POST["password"]) . "') LIMIT 1;";
    	$r = mysql_query($q);
    	$num = mysql_num_rows($r);
    
    	if($num == 0) {
    		die("Incorrect Username or Password, please check your credentials!");
    	} else {
    		$row = mysql_fetch_row($r);
    		$_SESSION["valid_id"] = $row[0];
    		$_SESSION["valid_user"] = $_POST["username"];
    		$_SESSION["valid_time"] = time();
    		Header("Location: main_interface.php");
    	}
    }
    } else {
      echo "<form action=\"?op=login\" method=\"POST\">";
      echo "Username: <input name=\"username\" size=\"15\"><br />";
      echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
      echo "<input type=\"submit\" value=\"Login\">";
      echo "</form>";
    }
    ?>
    

     

    Cheers!

  10. If it is a small amount of binary data, you could use base64_encode and send it via GET.

     

    Indeed I am aware of that, the problem is that the amount of data transferred is rather variable.

    Due to the nature of the entry script, the data can be a few bytes big for a message or a few megabytes big for an attachment.

    For the later case, it is much easier to transfer a 100mb file rather than a 133mb one. And these all exclude the time needed to encode the files and strings ;)

     

    Thanks for the reply anyway ;)

  11. Hello i am new here, and new to php too.

    I try to learn php from about 20 days, and i am getting stuck in something, somebody asked me to make a program that will produce the following output, i have to use a nested for loop:

    1

    22

    333

    4444

    55555

    ........etc

     

    The code for is:

    for($a=1;$a<10;$a++)
    {
       echo "<br>";
    
       for ($b=0;$b<$a;$b++)
       echo $a;
    
    }

    I do know this is something elementary, but really i cannot understand how it works is there any saint that will comment the code and explain step by step whats happening there?

    Thank you.

     

    In addition to what sunfighter said, the nested loop still acts even though it doesn't have the curly brackets ({ and }) after it.

  12. Hey guys.

    Sorry to start asking questions being such a new member but this just suddenly came up.  :P

    I have a php script that needs to send binary data to another php script via HTTP.

    The data can be transferred through the methods GET and POST, preferably POST and preferably not as a file.

     

    The problem is that I have tried a number of ways to do this but every time the data seems to be corrupted. Some bytes stay the same but others disappear or change. I guess that they transfer through ASCII mode instead of BINARY but couldn't find any way to fix this.

     

    Any help would be deeply appreciated.

    Cheers.

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