Jump to content

MDanz

Members
  • Posts

    728
  • Joined

  • Last visited

Posts posted by MDanz

  1. I'm attempting to reply to an email with php.  I use php imap to fetch the email from the mail server and get the `message-id`.. i'm attempting to reply to the email but the email still shows up as a new message rather than a reply with threaded messages?  

     

    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to email: ' . imap_last_error());
    $emails = imap_search($inbox,'ALL');
    
    if($emails) {
    
    rsort($emails);
    
    foreach($emails as $email_number) {
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message_id = $overview[0]->message_id;
    $references[] = $overview[0]->message_id;
    
    }
    
    $references = implode(" ",$references);
    
    $headers = "From: <test@domain.co.uk> \r\n";
    $headers .= "In-Reply-To: $message_id\r\n";
    $headers .= "References: $references\r\n";
    $headers .= "Content-Type: text/html;\r\n";
    $subject = "testing";
    $message = "test message2";
    mail( "test2@domain.co.uk", $subject, $message, $headers );

    How do i solve?  I'm using the headers from http://www.jwz.org/doc/threading.html.

  2. You can use %{HTTP_HOST} in a RewriteCond to detect the domain name, and RewriteRule(s) specific to that domain name. But it seems like each WP "site" should have it's own .htaccess and not one to run them all.

     

    .htaccess files cascade.

     

    Like if you had:

    /public_html/.htaccess

    /public_html/site1

    /public_html/site2

     

    That .htaccess at the root (public_html) would affect both the /site1 and /site2 dirs. Instead you'd want a separate htaccess to be within each of the /site1 and /site2 dirs. This would be more clean with each site having it's own htaccess file, and then you wouldn't have to muck around with domain specific rules which can get very complex the more sites you're trying to control with a single htaccess file.

    The way my clients website is set up it has

     

    /public_html/website 1

    /public_html/website 2

    /public_html/wp-content

    /public_html/website 3

     

    The website i want to mod rewrite on is /public_html/wp-content.  If i put a .htaccess file in /wp-content will that override the .htaccess file in the public_html folder?

     

    Thanks for help

  3. I don't understand how you can have stuff "written for each domain", and at the same time not know which domain each was written for.

    It's an assumption, in my .htaccess file in the root folder i have several of the below code written.  So i don't know which one to change for the specific domain.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Is there a workaround of putting .htaccess in wp-content folder?

  4. I have multiple folders(domains) in my public_html folder. In my public_html folder i have a .htaccess file. I want to do mod rewrite on a specific domain e.g. www.test.com


    Here is the mod rewrite wordpress has written for each domain



    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    The above code is in my .htaccess file multiple times, so i don't know which one to edit. I want to add the below code to the domain www.test.com but i don't know which one to edit.



    RewriteRule ^page/(.*) ads/page/$1 [R=301,L]
    RewriteRule ^page/(.*)/ ads/page/$1/ [R=301,L]

    What is the solution? Any help, greatly appreciated.


  5. OK...Can the queries have different amount of JOINS?

     

    e.g.

    SELECT child.id, child.name, child.colour FROM fruit child
    LEFT JOIN tree parent on parent.type=child.type
    LEFT JOIN country parent2 on parent2.name=parent.country
    UNION
    SELECT child.id, child.manufacturer, child.colour FROM car child
    LEFT JOIN country parent on parent.name=child.country
    ORDER BY colour
  6. I'm trying to do a following feed. This feed includes posts and comments that the user is following.

    The first 3 following types are in the content table and the last following type is in the comments table.

     

    This query fetches the first 3 following types successfully.

    $construct = $connectdb->prepare("SELECT parent.*
    FROM `content` as parent
    JOIN followers ftable on (
    (ftable.parent_id=parent.sid AND ftable.userposts='1')
    OR
    (ftable.`parent_id`=parent.pageid AND ftable.topic='1')
    OR
    (ftable.parent_id=parent.pageid AND ftable.page='1')
    ) AND ftable.userid=:userid
    WHERE parent.deleted='0'
    GROUP BY parent.id
    ORDER BY parent.posted DESC");

    This query fetches the following comments type successfully

    $construct = $connectdb->prepare("SELECT parent.*
    FROM `comments` as parent
    JOIN followers ftable on ftable.parent_id=parent.postid AND ftable.comments='1' AND ftable.userid=:userid
    WHERE parent.deleted='0'
    ORDER BY parent.posted DESC");

    How do i combine the two queries? In this feed i want the results to be ORDER by posted DESC.

     

  7. I always have trouble reading shorthand statements, as i am used to always using brackets. So when i view someones code and they use shorthand, i get confused.  Can i get a clear explanation on the example below:

    if ( have_posts() ) : while ( have_posts() ) : the_post();
    					the_content();
    					
    					endwhile; else: 
    					
    						echo "<p>Sorry, no posts matched your criteria.</p>";
    					
    					endif;
    

    I've always been accustomed to using brackets, so i have trouble understanding the above quickly.

  8. I've always used brackets but now switching to WordPress alot of the code doesn't use brackets in if statements and loops.

    <?php
    while (have_posts()) : the_post();
    the_content();
    endwhile;
    ?>

    How does this look with brackets?

     

    Also i see alot of question marks, i know question marks and colons are another way of coding, for example

    if($one == $two) {
    $yes = 1;
    } else {
    $yes = 2 ;
    }

    Any help to get me to understand this

  9. I just installed wamp, so i can test my website offline. Now i get numerous Undefined index or Undefined variable errors, which i know how to fix. Now logging in works online but with wamp it doesn't work. The code isn't wrong. I imported the database online to offline. I've pin pointed what is wrong but don't know how to solve it.

     

    here is the code where i test if the login details are correct.

    $Blowfish_Pre = '$2a$05$';
    $Blowfish_End = '$';
    $hashed_password = crypt($password, $Blowfish_Pre . $salt . $Blowfish_End);
    
    //check to see if they match
    if ($username==$dbusername&&$hashed_password==$dbpassword){
    

     

    Offline the echoed $hashed_password for the account is

    $2pozHhRA6bDM

     

    Online the echoed $hashed_password for the account is

    $2J7rPSsTYb1Q

     

    I've determined crypt is working differently online than it is offline? I am using the same php version both online and offline(php 5.2.17), Why is this and how can i solve it?  I've been stuck on this all day.  My website works perfectly online though.

     

  10. I currently have it that when a user logs in their username and userid are stored in a cookie. As this isn't the most secure method i now plan on changing the method;

     

    When the user logs in, a unique token is saved in the cookie. The username, userid, banned boolean and unique token are stored a session. The token in the cookie has to match the token in the session to be logged in.

     

    I've thought about storing the token in the database? Alot of times in my code i quickly require the username and userid, so storing in a session is the most logical idea to me instead of always querying the database.

     

    Anyway, is my method appropriate?; if not, what is a proven method?

     

    I understand that if i want to do 'remember me'  i have to have the token stored in the db?

     

    Any help appreciated.

  11. The below prepared statement doesn't insert into the database.

     

     

      $sid =1;
        $sid2 = $GET['sid2']; //empty
        $position = 0;
        $name = "John";
    
    $new = $connectdb->prepare("INSERT INTO `table1` VALUES ('',:sid,:sid2,:position,:name)");
    				$new->execute(array(':sid'=>$sid,':sid2'=>$sid2,':position'=>$position,':name'=>$name));

     

     

    When i add quotations to execute array values, then the insert works. 

     

     

     $new->execute(array(':sid'=>"$sid",':sid2'=>"$sid2",':position'=>"$position",':name'=>"$name"));
    

     

    What i want to know is by adding quotations does this affect PDO's sanitization? 

  12. If someone rides in on a session id, they will get the regenerate code as well.

     

    I think the most common way is to use tokens.  Where tokens are set in the URL (usually a md5 hash of browser and time), then checked against the same token saved in the session.

     

    I don't understand "Where tokens are set in the URL"?  This would be easier for me to understand with a full example. 

     

    Do i have to md5 has the session name? 

     

    $var = md5(rand()*time());
    $_SESSION[$var]=1; //logged in
    

     

    "set in the URL"?  ..i'm totally confused right now..

  13. I've looked everywhere and haven't found a clear step by step tutorial on how to secure sessions/cookies.  Here are snippets of my code, i'd like to know how i can improve on session security to prevent fixation/hijacking and cookie safety.  This is code for the user login system.

     

    login.php

    if ($username==$dbusername&&$hashed_password==$dbpassword)
    			   {
    
    					setcookie('username[0]',$username,time()+(60*60*24*365));
    					setcookie('username[1]',$userid,time()+(60*60*24*365));
    
    					if($admin=='1') {
    						$_SESSION['admin'] = 1;
    					}	
    
    					$_SESSION['logged-in'] = 1;
    
    				   header( 'Location: ' . $return );
    
    
    			   }
    

     

     

    logout.php

    $time = time()-(60*60*24*365);
    
    setcookie('username[0]', '',$time);
    setcookie('username[1]', '',$time);
    unset($_COOKIE['username']); 
    unset($_SESSION['logged-in']);
    unset($_SESSION['admin']);
    

     

    I call session_regenerate_id() on everypage, is that correct to stop session fixation/hijacking?

    session_start(); session_regenerate_id();
    

     

    php.ini

    session.use_trans_sid = 0
    session.user_only_cookies = 1
    

     

    Can you please tell me what i should do to improve on this? 

  14. I'm trying to do a query that if mike isn't in the three highest bids for a keyword, then display the row(row that has been outbid).  I tried below but i get no results.  I should get rows with id 4 and 7. btw a keyword can be bidded on more than once.

     

    $construct = "SELECT * FROM `temp-advertise` WHERE username='mike' AND bid <
    			(SELECT min.bid FROM `temp-advertise` min LEFT JOIN `temp-advertise` min2 on min.keyword=min2.keyword WHERE min.username='mike' ORDER BY bid DESC LIMIT 2,1)";
    
    
    id  | username| keyword | bid   |
       1 |  mike |  one     |  7    |
       2 |  tomm |  one     |  4    |
       3 |  cedr |  one     |  6    |
       4 |  mike |  two     |  1    |
       5 |  tomm |  two     |  5    |
       6 |  harr |  two     |  5    |
       7 |  mike |  one     |  3    |
       8 |  harr |  two     |  3    |
    

     

    i tried another query and also get no results

     

    $construct = "SELECT child.* FROM `temp-advertise` child LEFT JOIN `temp-advertise` parent on child.keyword=parent.keyword
    			WHERE child.username='$username' GROUP BY child.keyword ORDER BY child.bid DESC LIMIT 2,999";

  15. The query below is correct.  It returns the rows `paul` and `rick` because they have the highest rating of the child rows.  This was solved for me with the below link.  I am having trouble understanding the query.  I understand joins, what i don't understand is `t2.rating is null`? 

     

    http://sqlfiddle.com/#!2/97e60/2

     

     

     

     

     select t1.* from mytable t1
            left join mytable t2
            on t1.parentid = t2.parentid and t1.rating < t2.rating
            join mytable parents
            on parents.id = t1.parentid
            where t2.rating is null AND parents.name like '%mike%'

     

    `t1.rating < t2.rating` attaches the highest rated values to the LEFT table.  I know `t2.rating is null` means t2.rating is false but i have no idea what it is doing in the query?  Does that mean it removes from t1 where there isn't a match in the LEFT JOIN query?

     

    my head hurts... the simpler the explanation the better.

  16. Ok, as easiest as i can explain.

     

     


    •  
    • There are many child.sid to parent.id.
       
    • There are many child.nid to child.sid
       
    • There are many child.id to child.nid

     

    child.id is just the id of a child row. And each row has rating column.

     

    In the query i'm grouping by child.nid. But the results that are being returned are the first entry(lowest child.id) for each nid. What i want is the highest rated child.id for that nid.

     

    $construct =  "SELECT child.* FROM outcomes child 
        JOIN outcomes parent on parent.id=child.sid JOIN    
        WHERE (parent.name LIKE '%$search%') GROUP BY child.nid,child.sid
        ORDER BY child.rating DESC";

     

    I've tried ORDER BY child.rating DESC but this needs to happen before the GROUP BY child.nid.

     

    Any idea how to solve this problem?

     

  17. this is what i want

     

    +----+-----------+----------+
    | id |       sid |      num |
    +----+-----------+----------+
    |  1 |        15 |      one |   
    |  2 |        15 |      two |   
    |  3 |        17 |    three |   
    |  4 |        17 |     four |  
    

     

    this is what i am getting

     

    +----+-----------+----------+
    | id |       sid |      num |
    +----+-----------+----------+
    |  1 |        15 |      one |   
    |  3 |        17 |    three |   
    

     

    basically i want to LIMIT per `sid`.  so LIMIT 2 will be two different `sid` not two rows.

  18. With the below query I'd get the results one and three. How do I get the results for `sid`; 15 and 17? I can't use a WHERE because I won't know the `sid`.

     

    A better way of explaining is, how do I LIMIT per `sid` without grouping?

     

    mysql_query("SELECT *
                 FROM   `mytable`
                 GROUP  BY `sid`
                 ORDER  BY `sid` ASC
                 LIMIT  0, 2");
    
    +----+-----------+----------+
    | id |       sid |      num |
    +----+-----------+----------+
    |  1 |        15 |      one |   
    |  2 |        15 |      two |   
    |  3 |        17 |    three |   
    |  4 |        17 |     four |  
    |  5 |        18 |     five |   
    |  6 |        18 |      six | 

  19. How do i display the image uploaded after the form has been submitted? After the form is submitted it will be a preview page, so i'm not storing the image type BLOB in MySQL yet. How do i display $_FILES['image']?

     

    <?php
    
    if(isset($_POST['submit'])) {
    
    //preview page
    
    $info = getimagesize($_FILES['image']['tmp_name']);
    $imagetype = $info['mime'];
    $tmpname = $_FILES['image']['tmp_name'];
    $fp = fopen($tmpname,'r');
    $data = fread($fp,filesize($tmpname));
    $data = addslashes($data);
    fclose($fp);
    
    } else {
    ?>
    
    <form enctype="multipart/form-data" action="http://www.example.com/submit" method="POST">
    <input type="file" name="image" value="" size="50" />
    <input type="submit" name="submit" value="submit" />
    </form>
    
    <?php
    }
    
    ?>
    
    

  20. so you mean like this

     

    foreach($rowids as $value) {
    
    
            $select = mysql_query("SELECT voteid FROM vote WHERE username='$username' AND voteid='$value' LIMIT 1",$this->connect);
    
                if(mysql_num_rows($select)==0) {
    
            $insert = mysql_query("INSERT INTO vote (id,voteid,username) VALUES ('','$value','$username')",$this->connect);
    
                }
            }

     

    i still need another method rather than a foreach loop.  Could unique index or insert ignore work?  voteid is the id of a row from a different table btw.

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