Jump to content

Tandem

Members
  • Posts

    251
  • Joined

  • Last visited

    Never

Everything 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. RewriteEngine On RewriteCond %{HTTP_HOST} ^www RewriteRule (.*) http://site.com/$1 [R=301]
  3. Check out the date function on php.net, there's a table of different formats. date("jS M", time()) for example would return "28th Jul".
  4. Oops, missread what you were saying, my apologies.
  5. 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.
  6. Nope it's not only for small websites. Much of Facebook and Wikipedia are written in it, according to the PHP article on wikipedia. http://en.wikipedia.org/wiki/PHP#Usage
  7. Tandem

    preg_replace

    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.
  8. Thanks man. I've just read through 3 tutorials that are all entirely wrong then Much appreciated.
  9. 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.
  10. 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.
  11. Sorry, i wrote something completely wrong, disregard this post.
  12. put error_reporting(E_ALL); if you don't have any error reporting enabled via your php.ini
  13. 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.
  14. I'm not sure how to find the creation date of a table via command line, but if you use phpmyadmin, the creation date of a table is displayed when you view the structure of the table.
  15. You'll need to post the full code. Also it'd be helpful if you could put [code.][./code] (remove the dots) around your code so the syntax will be highlighted. Thanks
  16. 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: You might want to google it for extra options though.
  17. mysql_query() only returns false if there is an error, so it'll still return true even if there are no results returned. As cooldude832 said, you'll need to count the results first.
  18. What happens? Do you get any errors? Or just nothing?
  19. Thanks for that, i'll give it a try.
  20. 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.
  21. 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.
  22. How do i restore a database from windows command line? I have the dump file, just don't know how to do it, and can't find any help on google. Thanks in advance.
  23. 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.
  24. Thanks. Is it capable of formatting my code for me? I can't see it on the site, and i've downloaded it and can't figure it out. Still looking for others to try too if anyone else has any reccommendations!
×
×
  • 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.