Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. When I want to do something like that I usually set a session variable on the sending page and then check if the session is set when the next page loads, then unset the variable when the page loads so they can't refresh...

     

    They could just close the browser, you could also just set a cookie with an expiration of 2 hours, or a database time field.

     

    Avoid Javascript whenever possible, or paranoid folks like me can't use your site because js is disabled :P

     

    Just giving it an example, if you're just disabling the submit button, oh well, you could still use the site.

  2. If you want to just disable the form just add some javascript.

     

    <form name=name action=file.php method=post onSubmit="document.name.submit.disabled=true">
    <input type=submit name=submit value="Send Password">
    </form>
    

     

    If you want to use pure php for this, just set a session and, if you want to limit the amount of time between for them to resend/change their password.

     

    Say you set the session as $_SESSION[pw_time], and the value was time()

     

    Just do this:

     

    if($_SESSION[pw_time]){
         $diff = time()-$_SESSION[pw_time];
    
         if($diff < 7200){ //2 hours
         //no form
         }else {
        //form
         }
    }else {
    //form
    }
    

  3. SMS can be sent via email by addressing the email to phonenumber@provider.com...you should be able to find the @provider.com part from google...for example, verizon is 123456789@vzw.com I think.

     

    Remember that SMS is limited to 160 characters.

     

    Some Verizon is:

     

    ACCOUNT@vtext.com

  4. The function mysql_real_escape_string, will escape all apostrophes, making the input value more secure.

     

    To retrieve the data back to its normal state use stripslashes.

     

    <?php
    $sql = "SELECT * FROM myTable";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    $msg = stripslashes($row[message]);
    echo "Message: $msg";
    ?>
    


  5. I made a file editor, the only problem is that, when I try to change the file contents it just added that content I changed it to the actual file content.

     

    Say:

     

    if file abc.php's content was:

     

    hello
    

     

    and i wanted to change the WHOLE file to say goodbye and when I hit save, it would make the contents:

     

    hellogoodbye
    

     

    CODE:

     

    edit.php

     

    <?php
    
    
    $loadcontent = $_GET['page'];
    
    
    
    if ( isset ( $_POST['savecontent'] ) && trim ( $_POST['savecontent'] ) != '' )
    {
    
    $content = $_POST['savecontent'];
    
    $fp = @fopen ( $loadcontent, 'w' );
    if ( $fp )
    {
    	fwrite ( $fp, $content );
    	fclose ( $fp );
    }
    }
    else
    {
    $fp = @fopen ( $loadcontent, 'r' );
    $content = htmlspecialchars ( fread ( $fp, filesize ( $loadcontent ) ) );
    fclose ( $fp );
    }
    
    ?>
    <form method=post action="change.php">
    <input type=hidden name=filename value="<?=$_GET

    ?>">
    savecontent
    <textarea name="theText" cols="70" rows="25"><?=$content;?></textarea>
    <br>
    <input type="submit" name="save_file" value="Save">
    </form>
    

     

    change.php

     

    <?
    ob_start();
    $filename = $_POST[filename];
    $theText = $_POST[theText];
    
    $theText = stripslashes($theText);
    
    $data = fopen($filename, "a");
    
    fwrite($data,$theText);
    
    fclose($data);
    
    echo "File created or updated";
    sleep(3);
    header("Location: edit.php?page=$filename");
    ob_end_flush();
    ?>
    

  6. $insert = ("INSERT INTO news (title, date, content)
    VALUES ('$title', '$date', '$content')");
    $add = mysql_query($insert)
    or die(mysql_error());
    

     

    change to

     

    $insert = "INSERT INTO `news` (`title`,`date`,`content`) VALUES('$title','$date','$content')";
    $add = mysql_query($insert) or die(mysql_error());
    

     

    You also want to make sure your variables actually have a value defined to them, so before you do the query, echo off the variables.

  7. If you still want to do it like that, you can do:

     

    $content = $_GET['content'];
    //$content = mysql_real_escape_string($content);
    //only if you're pre-connecting to a database
    if($content){
    $content_new = "$content.htm";
    
    if(file_exists($content_new)){
    include "$content_new";
    }else {
    echo "This file does not exist";
    }
    }
    

  8. Just do something, like:

     

    $sql = "SELECT * FROM `table` WHERE `id` =#"; //# to the variable for their ID
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    
    echo "<select name=\"country\">\n";
    $sql2 = "SELECT * FROM `countries`";
    $res2 = mysql_query($sql2) or die(mysql_error());
    
    if(mysql_num_rows($res2) > 0){
    while($row2 = mysql_fetch_assoc($res2){
            if($row[country] == $row2[country]){
    	$var = " SELECTED";
    	}else {
    	$var = "";
    	}
            
    echo "<option value=\"$row2[country]\"$var>$row[country]</option>\n";
            }
    }else {
    //your own countries
    }
    
    echo "</select>\n";
    

  9. Just a suggestion, but why don't you just store it in a cookie or session?

     

    Make three cookies [or] sessions: uid (being the users unique id), topic (being the topic id), time_topicid (being just time()).

     

    Name the cookies/sessions after the topic id.

     

    Then just go to your forums, add something:

     

    if($_COOKIE['TOPICID'] || $_SESSION['TOPICID']){
    echo "Read: ";
    }else {
    echo "Unread: ";
    }
    

     

    If the cookie/session doesn't exist while going to the topic just add it.

     

    Then check the time, if the last post on that topic is greater than the time the person went to it, update the cookie/session to the new time. Within the IF statment posted above, you can add

     

    $time = "SOME QUERY TO FIND THE LAST TIME POSTED ON THAT TOPIC";
    if($_COOKIE['time_TOPICID'] < $time || $_SESSION['time_TOPICID'] < $time){
    echo "Unread: ";
    }else {
    echo "Read: ";
    }
    

     

    So basically the whole code would be:

     

    if($_COOKIE['TOPICID'] || $_SESSION['TOPICID']){
         if($_COOKIE['time_TOPICID'] < $time || $_SESSION['time_TOPICID'] < $time){
         echo "Unread: ";
         }else {
         echo "Read: "
         }
    }else {
    echo "Unread :";
    }
    

     

    NOTE: It may not work since I just thought of it now.

     

    EDIT: This could also save database space ;)

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