Jump to content

RussellReal

Members
  • Posts

    1,773
  • Joined

  • Last visited

Posts posted by RussellReal

  1. Not with php, atleast I'm 90% sure you can't with php, unless you modify your apache config files, which you probably can't due to permissions issues..

     

    what you CAN do, is contact your hosting provider, ask them to impliment wildcard subdomains..

     

    and so whenever you go to

     

    whateverYouWant.yourdomain.com

     

    it'll know to go to whichever directory, in there you use modrewrite (htaccess rewrite engine) to detect the subdomain and reform the request to something similar to: yourdomain.com/whateverYouWant/

  2. why would you die() on errors, you should pass it to an error object, and check if any errors have accumulated every step of the user verification process.

     

    and your use of the :: operator is completely wrong, you don't want the information in a user class to be static, you want it to be dynamic, which you'd use -> operator for.

  3. run the cron job for every 2 seconds or 3 seconds

    The minimum interval for a cronjob is 1 minute.

     

    Ken

     

    yes, I know, but that means 1 script is being ran every (24*60*60) times per day, to do something that doesn't need to be completely automatic :) 3 seconds is perfectly fine I thought, but you could run it every 1 second for sure..

  4. I am trying to parse an XML file and there are some values that contain a : as you can see below.

     

    $rss_xml = SimpleXML_Load_String($rss_data);
    
    foreach ($rss_xml->channel->item as $item) {
    	echo $item->title;
    	echo "<br />";
    	echo  $item->link;
    	echo "<br />";
    	echo  $item->description;
    	echo "<br />";
    	echo  $item->g:price;
    	echo "<br />";
    	echo  $item->g:image_link;
    	echo "<hr />";
    }

     

     

    For some reason because of this : I get the error.

     

    HP Parse error:  syntax error, unexpected ':', expecting ',' or ';' in /home/blah/blah/blah/index.php

     

    I have tried escaping it with a \ and also quoting the last element in the echo but it still will not have it.

     

    Any suggestions.

     

    Thanks

     

    you're probably trying to use the ::  operator instead of  ':', however, that will not work I don't believe, replace your ':' with '->' and see where that gets you :)

  5. Sorry, I guess it would help to say what I am trying to do.  When you choose a month it is supposed to populate the reservations select box.  Then they would fill the remainder of the form and then it would post to reversend.php upon submit.  I had it working separately, but it would not post in any browser except Firefox 3.6.  I guess wc3 does not allow form inside form anymore....

     

    You should look at http://jquery.com/ it makes this so so easy, but if you wanna do it like this, you will have to

     

    from reserv_test.php do something like this code:

     

    <?php
      // connect to db
      $reservations = array();
      $q = mysql_query("SELECT r_id FROM reservations WHERE r_taken = '0' AND r_month = '{$_POST['month']}'");
      while ($x = mysql_fetch_assoc($q)) {
        $reservations[] = $x;
      }
      echo json_encode($reservations);
    ?>
    

     

    and in the js

     

    you will get your response from the server, if you're using jQuery it will already process the JSON from the response, however, if you're using str8 ajax in javascript, you'll need to execute your response

     

    var reservations = eval('('+xmlHttpRequest.responseText+')');

     

    and there you go, reservations will hold an object of all available reservations! :)

  6. what you should do, buy a cheap $2 webhosting that supports cron, run the cron job for every 2 seconds or 3 seconds

     

    the php file would simply be to check if there are any queued calls... then dispatch them, then wait to be activated again..

     

    whichever company you work for wouldn't have a problem with paying the extra $24/year for this to work out..

     

    thats the easiest sollution, aswell as most practical.

     

    however, if you want to use sleep(), for over 12 hours, you're most likely gonna want to double check with Yahoo! Small Business if its okay

  7. I just have a general question about when other programmers remove rows older than say a year old....

     

    Do most of you:

    1) set up a CRON job to run daily at 3:00am

    2) Add a routine at login for each user

    3) Add a routine when a user moves into a certain portion of the application

    4) A maintenance routine that an administrator manually has to envoke

     

    Or is there another way...I have done some research but most of the things google has showed me is the how not when to do this...

     

    I'd say the best would be 1 or 4.. 1 would be the best choice for me tho :)

  8. I have no idea with ajax... is there any php codin...

     

    Or can anyone help me with the code in ajax.

     

    This is what I would recommend:  http://jquery.com/

    http://api.jquery.com/category/ajax/

     

    You write a script that does session_start(), checks that there's a valid user and if so, calls an update function you write that will update the status of the user -- usually via a datetime column in the database named something like lastseen.

     

    In your jquery you make calls to this script based on the setInterval() javascript function. 

     

    One reason not to use the onbeforeunload() event as suggested by russelreal, is that this would be problematic in certain circumstances where for example, someone opens up multiple tabs to your site for the same session, which is easy to do with current browsers.  If you assume that because someone closed a tab they were logging out, you could get in a situation where you logged someone out who still had an open window on your site.

     

    yes but they would be inactive until they visit another page anyway :)

     

    when they visit the next page their session will be touched and they'll be "active" again.

  9. I kinda see where you are going but I'm getting error:

    PHP Notice: Undefined variable: ref in C:\inetpub\wwwroot\test.php on line 5

    on page 1

     

    this is how page 1 looks at the moment:

    <?php
    session_start();  
    $a = rand(1,1000);  
    for ($i = rand(1,10); $i < rand(11,20); $i++) $a += rand(1,rand(35,1000)); // KINDA ensures a random number  
    $ref &= $_SESSION['tabs'][$a];  
    $ref = array(); // use $ref for the rest of STEP 1
    
    $list = "<table>";
    $list .= "<tr>";
    $list .= "<th colspan=\"4\">Search for a Customer</th>";
    $list .= "</tr>";
    $list .= "<tr>";
    $list .= "<td></td><form action=\"test2.php\" method=\"post\">";
    $list .= "<td>Forename (Leave blank for all)</td>";
    $list .= "<td>Surname (Leave blank for all)</td>";
    $list .= "<td></td>";
    $list .= "</tr>";
    $list .= "<tr>";
    $list .= "<td>Name Search</td><form action=\"search_name.php\" method=\"post\">";
    $list .= "<td><input type=\"text\" name=\"forename\" size=\"25\"></td>";
    $list .= "<td><input type=\"text\" name=\"surname\" size=\"25\"><input type=\"text\" name=\"tab\" value=\"$a\"></td>";
    $list .= "<td class=submit><input type=\"submit\" class=\"submit\" value=\"Search\"></form></td>";
    $list .= "</tr>";
    $list .= "</table>";
    echo $list
    ?>

     

    I'm sorry, where it says &=, change that to =&

  10. longpolling #1 BEST answer to this, but server limitations and browser limitations mess you up :)

     

    for example, google chrome only allows 2 or 3 live connections at a time, which means if they have 3 or 4 instances of your web app, one of those will be inactive until it can secure a slot to start a connection.

     

    server limitations vary but its mostly because servers offer limited connections at the same time..

     

    an example of a longpoll is simply:

     

    1. request a php file from your server (longpoll.php) with javascript and wait for a return

     

    2. in longpoll.php you will throw yourself into an infinite loop, everytime the loop LOOPS you will check the database for new results, messages, etc. IF and WHEN you get a return from the database, you will return it to the browser..

     

    3. browser will get back data or the connection will time out, handle the data you've just received, be it a new message or a friend coming online etc.

     

    4. repeat steps 1-3 immediately

     

    this will get your live chat on the right track :)

  11. RusselReal,

      Those are not the same things at all.  A timed ajax call can update status every 30 seconds or minute or 5 minutes.  That technique is frequently used to support html/near realtime chat pages.

     

    yes I know what AJAX is, but AJAX is simply Javascript with use of XML Streams... I have used the same general idea on one of my sites as what you have mentioned, but I stuck to the Original Poster's guidelines with my answer.. I wasn't bashing your answer. He wanted to know when the user changed URLs, yes ofcourse you can't actually GET the new URL, but you can use this to know when the user:

    A. CLOSES THE BROWSER

    B. NAVIGATES AWAY FROM THE CURRENT PAGE.

     

    That seems to be his ultimate goal here :) then he could use AJAX inside of the onbeforeunload to send a request to the server, the server doesn't even have to give a response, make it a 1 way transaction saying that the user has left that page :)

     

  12. No you can't detect if someone changes the url.

     

    What you can do is utilize ajax to make periodic updates to a script on your site, which you can use as an "activity" monitor.

     

    Very few people actually logout of a website -- they just navigate away or close the browser.  You should not depend on a logout.

     

     

    well if you're gonna go with ajax, you could just go with an onbeforeunload event... but I don't know the browser support of that event.

  13. same issue exists IF you use COOKIES to handle PHPSESSID, but if you append the PHPSESSID to the url, than you can basically have multiple sessions per user..

     

    but asside from the above, which would be easier, if you want to limit 1 session per user, and just thread the session out to accommodate multiple tabs you could use the same logic as the first thing I mentioned..

    With minor differences..

    When a user goes to step1, set a variable in 2 places... E.G.

     

    <?php
      session_start();
      $a = rand(1,1000);
      for ($i = rand(1,10); $i < rand(11,20); $i++) $a += rand(1,rand(35,1000)); // KINDA ensures a random number
      $ref &= $_SESSION['tabs'][$a];
      $ref = array(); // use $ref for the rest of STEP 1
    ?> 

     

    ^^ in the form of step 1, 2 AND 3.. include a hidden input like so:

    <input type="hidden" name="tab" value="<?php echo $a; ?>" />

     

    and then in STEP 2 get the current $ref for the current tab by doing this:

     

    <?php
    session_start();
    $ref = $_SESSION['tabs'][$_REQUEST['tab']];
    ?>
    

     

    the only downside to method #2 is if a user hits the backbutton all the way to step 1, a new tab id will be generated, and then the session file could get huge if that guy likes to refresh on step 1 aswell.. a whole lot :P

     

    so theres drawbacks to both, you can decide which one you like better

  14. sessions are the best possible solution..

     

    how a session works is easy to understand, and you'll maybe be able to use them better.

     

    #1 when you call session_start() it will look thru the REQUEST variables (Cookie, Post, Get) looking for PHPSESSID. When PHP finds this variable it will access it find the string contained within, and open up a file.. if there IS NO PHPSESSID then it will create that variable (which is why it needs to be called before any output.. setting a COOKIE requires no output to be sent)

     

    #2 once the file is located which contains your user's SESSION.. it is opened and loaded into a regular-not-so-special variable called $_SESSION

     

    #3 then you will use $_SESSION just like you'd use any other array.. except, anything you put into $_SEsSIOn or take away from $_SESSION will be recorded inside of that user's session file :).

  15. Very close, RussellReal, but that doesn't take care of the multiple possible line endings line \r\n, \r, AND \n. Here is my whack at the code.

     

    $values = preg_split('/(\r\n|\r|\n)/', $_POST['text_area']); //this gets an array where each item on its own line is an element in the array
    
    $query = "INSERT INTO  `database_name`.`table_name` (`value1` ,`value2` ,`value3`) VALUES "; //prepare the first part of the query with the fields
    
    foreach($values as $index=>$value){
              $value = explode("-", $value); //make the array
    
              $query .= "('{$value[0]}',  '{$value[1]}',  '{$value[2]}'),"; //add that item
    }
    
    $query = rtrim($query, ","); //remove the trailing comma
    
    // Now add your own code to execute the query.
    

    :D

    --

    techdude

     

    we are not talking about a text file, we're talking about a text input.. its always just an \n

     

    and either way.. \r is just a carriage return \r\n is not a different way of a new line.. if anything even if there happened to be a carriage return found.. a simple trim() would do fine when you add my lines back to the main array..

     

    so gf <3

  16. $x = explode("\n",trim($_POST['text_field']));
    foreach ($x as $line) {
      $y = explode("-",$line);
      mysql_query("INSERT INTO `table` (common_name,genus_name,native_to) VALUES('{$y[0]}','{$y[1]}','{$y[2]}');");
    }
    

     

    however this could also be done with only ONE insert query.. but it would be handled something like this:

     

    $x = explode("\n",trim($_POST['text_field']));
    foreach ($x as $key => $line) {
      $vals = ($y = explode("-",$line));
      foreach ($y as $key => $value) {
        $vals[$key] = "'{$value}'";
      }
      $x[$key] = '('.implode(",",$vals).')';
    }
    $x = implode(',',$x);
    mysql_query("INSERT INTO `table` (common_name,genus_name,native_to) VALUES{$x}");
    

  17. How would I add a loop to this PHP coding? I want to make it so that after 'I AM THOMAS' it will loopback to 'HELLO WORLD' and repeat the same cycle infinitely.

     

    How do I make a loop for PHP? Is this right?

     

    <?PHP

    require ("config.php");

    exec("mode com3: BAUD=9600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off");

    $fp =fopen("com3", "w");

    while (true){

    fwrite($fp,"HELLO WORLD");

    fwrite($fp,"I AM THOMAS");

    sleep(5);

    }

    fclose($fp);

    ?>

     

     

    $x = true;
    while (true){
    if ($x) fwrite($fp,"I AM THOMAS");
    else fwrite($fp,"HELLO WORLD");
    $x = !$x;
    sleep(5);
    }
    

  18. I don't quite understand the question, but I'll try and help anyway (:

     

    From what I gather you just want simply a way to calculate a different shade of red, and a different shade of green, for each level of energy/entropy..

     

    ok!

     

    so heres how we'd go about doing this!

    <?php
    $levelMax = 256; // highest shade of any color in the RGB spectrum(?)
    
    /* change these whenever you want to */
    $x = 1.8;
    $y = 1.2;
    $max = 3;
    /* ^^ those are the editable things lol */
    
    $red = ($x / $max) * $levelMax; // tiered red
    $gre = ($y / $max) * $levelMax; // tiered green
    
    $color = imagecolorallocate($image,$red,$gre,0 /* blue change to whatever */);
    ?>
    

     

  19. Very cool. I have some studying to do. I've never seen some of what you're used here. Thanks. I'll get to work.

     

    np bro, I'll explain it :)

     

    IFNULL simply checks if parameter 1 is null, if it is, return parameter 2, if it isn't null, it returns parameter 1 :)

    (to make it make sense! IFNULL(param1,param2) )

     

    LEFT JOIN is an OUTER JOIN, INNER JOIN is self explanatory :)

     

    The difference between outer joins and inner joins, outer joins will not fail the selection if the ON parameter doesn't match, it will simply join a NULL ROW

     

    so basically if there is NO ROW in `icons` for the address 'playground' then it will instead of not pull a row for 'playground' it will pull playground from `nvc` and a null row from `icons`..

     

    so back to IFNULL, because IFNULL tests param1 against NULL, if `icons` doesn't have a row for the current `nvc` row, IFNULL(icons.icon,'defaultPicture.gif') will naturally return parameter2 which is the default picture for rows without a thumbnail :)

     

    I gotta run out :)! Thanks for choosing PHPFreaks for your PHP help <33 *got paid $5 to say that.. cough cough* *not really, I just love this forum!*

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