Jump to content

Tandem

Members
  • Posts

    251
  • Joined

  • Last visited

    Never

Posts posted by Tandem

  1. You're going to need to use sessions to store the data unless you want to store it in the GET request which is not a good idea. Store the current step that the person is on in the GET request however. Using if and else if statements to decide which form to display and which set of validation to use depending on what step they are on is what i would use personally.

  2. No ??? I think he's done that with mysql_num_rows function. IF == 1, means that they exist and they're correct.

     

    All that's doing is making sure that the persons login details are correct, not if they are actually logged in.

     

    NathanLedet's solution is correct, i believe.

  3. Hey guys, i'm having a problem using preg_replace:

     

    echo preg_replace('[^a-z0-9\-]+', "", strtolower(str_replace(" ", "-", $line[0])));

     

    $line[0] is a string that could be pretty much anything. I want to replace any spaces with a dash, set it to lower case, and then remove anything that isn't a letter, number or dash.

     

    The above is what i have thought would be correct, but it seems to just remove everything.

     

    I can't figure out what i'm doing wrong.

     

    Any help appreciated.

     

    Thanks.

  4. Hey guys,

     

    It's been a while since I got off my butt and wrote some php so i'm a bit rusty.

     

    I'm writing a login script. At first it appears to work fine, if you put in the right username/pw then you get up a little admin panel. But when I click any of the links for my admin-only pages, I get logged out right away. Each of the admin-only pages has a little included script which checks to make sure I have a session going, and taking me back to the login page if I haven't.

     

    So basically my problem is that my sessions appear to be only lasting for one page load, and I want them to last long enough to at least view another page :)

     

    Here's the login script:

    <?php
    include 'db.php';
    if ((isset($_POST['submit'])) && (!isset($_SESSION['username']))) {  		 //if form is submitted and you aren't already logged in
    if (ctype_alnum($_POST['username'])) {                           		//check the username is alphanumeric
    	$_POST['password'] = md5($_POST['password']);			   //convert the password to an md5 hash
    	$query = mysql_query("select username from login where username='$_POST[username]' and password='$_POST[password]'");
    	if (mysql_num_rows($query)>0) {
    		session_start();
    		$_SESSION['username'] = mysql_result($query, 0);
    	}
    	else {
    		$success = false;	
    	}
    }
    else {
    	$success = false;	
    }
    }
    include 'top.php';
    if ((isset($_POST['submit'])) && (isset($success))) {
    echo '<div id="error">Wrong Username/Password.</div>';
    }
    ?>
    <div id="tcontent"></div>
    <div id="content">
    
    <?php
    if (!isset($_SESSION['username'])) { 
    ?>
    <form action="login.php" method="POST">
    <center>
    Username: <input type="text" name="username" /><br />
    Password: <input type = "password" name="password" /><br />
    <input type="submit" name="submit" value="Submit!" />
    </center>
    </form>
    
    <?php
    }
    else {
    include 'adminlinks.php';	
    }
    ?>
    </div>
    <div id="bcontent"></div>
    <?php
    include 'bottom.php';
    ?>

     

    and the session check in case i've made an embarrassingly obvious mistake that only I can't see, is:

    <?php
    if (!isset($_SESSION['username'])) {
    header("Location: login.php");         //back to the login page
    }
    ?>

     

    Also in case it helps, my hard drive died not too long ago taking with it my apache/php installation, and this new installation is relatively untouched so i may need to mess with the conifgurations if it's not the code.

     

    Thanks guys.

  5. Oops, i think i might have been correct after all. I think you need to choose which database to perform your queries on.

     

    Try putting:

    mysql_select_db("DB NAME HERE", $mysqli);

     

    after your connection function.

  6. I'm going to assume you have a database already setup and just talk about the PHP. If you haven't just say.

     

    <?php
    
    // Firstly you need to connect to your database. If it fails, MySQL will generate an error for you.
    $conn = mysql_connect("http://example.com", "username", "password") or die(mysql_error());
    
    //Then you need to select your database.
    mysql_select_db('DATABASE_NAME_HERE', $conn) or die(mysql_error());
    
    //Here are your links that would be on the left. I'll leave the HTML that positions them to the left up to you.
    echo '<a href="http://example.com/index.php?data=apple">Apple</a>';
    echo '<a href="http://example.com/index.php?data=potato">Potato</a>';
    echo '<a href="http://example.com/index.php?data=carrot">Carrot</a>';
    
    //The ?data= part is passing a variable via the URL. The variable value is that of the link you've clicked.
    
    //Now for determining what to display, based on what the data variable's value is. The variable is stored in the GET global.
    
    if ($_GET['data'] == "apple") {
         //Display what you want to display for an Apple.
    }
    if ($_GET['data'] == "potato") {
         //Display what you want to display for a Potato.
    }
    if ($_GET['data'] == "carrot") {
         //Display what you want to display for a Carrot.
    }
    
    ?>

     

    Hope that helps.

     

  7. The .sql file isn't the actual database, it's a list of instructions for the MySQL program, written in SQL.

     

    To have MySQL execute the instructions, which i am going to guees will create a database, you can use the source command. I believe it works by typing:

     

    source (path to .sql file here)

     

    You might want to google it for extra options though.

  8. Hi,

     

    my site features a lot of user input, such as user profiles, and some forums that i wrote myself as well as many other similar examples. My problem is that if somebody enters a very long word, wider than the page width, it sort of screws up the page design, and generally causes me some annoyance whilst performing certain tasks.

     

    I'm wondering if there is a way to detect whether a string has any words longer than a specified length in it?

     

    I was thinking that perhaps using explode(" ", $variable), and then looping through the array and making sure that there are no words of longer than the length i want, but i can see that being quite slow

     

    Any suggestions or links to any help are appreciated.

     

    Thanks.

  9. md5 is for if somebody manages to hack into where you store your clients/customers/members passwords, that they will not be able to read the passwords or be able to use them for anything worthwhile. The security of md5 is debatable though as some claim they can decrypt it, but i am yet to see proof of this or see it for myself.

     

    If you want your page to be truly secure, like maybe if users are submitting sensitive info, such as credit card details, you need to look into SSL.

  10. Windows, Linux, Mac?

    Free, paid for?

     

    Windows, and i don't mind paying as long as the price is reasonable.

     

    I'm looking for something sort of like the Actionscript editor in Flash, but obviously for PHP rather than AS. Syntax Highlighting and auto-formatting are pretty much a must.

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