Jump to content

Tandem

Members
  • Posts

    251
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Tandem's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

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