Jump to content

Jerzxu

Members
  • Posts

    53
  • Joined

  • Last visited

Posts posted by Jerzxu

  1. spl_autoload_register expects a function that will be used to resolve your class name to a file to include. Your not passing it anything.

     

    I find it kind of weird that spl_autoload uses this functionality for namespaces. Numerous places online I've read mentioned that spl will look at the namespace and attempt to load it based on the namespace as if it were a directory structure.

     

    http://www.dreamincode.net/forums/topic/148935-php-53-namespacing-and-autoloading/ Example of autoloading with namespaces. Though this is done on windows though, not linux.

     

    Guess I will just specify a function to load it. Thanks.

  2. I did a search on the forums before posting this So I have been attempting to use spl_autoload_extensions('.php') to autoload my classes based off namespaces but it continually says that the namespace does not exist.

     

    Code I am using:

     

    spl_autoload_extensions('.php');
    spl_autoload_register();
    
    use Test\Systems\User as User;
    
    $usr = new User();
    

     

    The error I get is this: Class Test\Systems\User could not be loaded in..

     

    My files are exactly as named in the namespace. So

    Test > Systems > User.php

     

    I have also tried variations of that like:

    spl_autoload_extensions('.php');
    spl_autoload_register();
    use Test\Systems as Test;
    $usr = new Test\User();
    

    And so on. Nothing appears to be working.

     

    I looked around online and seen that at one point *nix systems couldn't use autoloading but apparently php 5.3.3 fixed this functionality. The server currently is running on 5.3.13 so I am not sure why this isn't working.

     

    Any insight would be appreciated.

  3. It does in your example. That's as far as I can go with the data you've provided.

     

    http://ekoverse.com/tests/test.php

     

    Doesn't seem to. Code for that page:

    <?php
    
    $page = file_get_contents('http://www.skinakiska.com/conditions/snow-report.aspx');
    $content = strip_tags($page);
    preg_match('/24(?:h| h)\s+\d+°(?:C|F)\s+\d+\s+cm/i', $content, $matches);
    
    $pattern = '/24(?:h| h)\s+\d+°(?:C|F)\s+\d+\s+cm/i';
    
    print "Matches: <br/>";
    print_r($matches);
    print "<br/><br/>";
    print "Pattern: <br/>";
    print $pattern;
    print "<br/><br/>";
    print "Content: <br/>";
    print $content;
    
    ?>
    

    Guessing it doesn't work due to the degrees symbol issue.

     

    I almost got what I needed by doing this RegEx:

    /((24 Hr|24 Hrs|24 Hour|24 Hours|24H|24 H).*?(\d+)?(cm| cm))/si
    

     

    Except the value I need, the 0, isn't appearing. Possibly due to a conflict of digits?

     

    The reason I need the RegEx to be like that is because there is numerous other websites that I will be looping through to get the same sort of data so the expression can't be just for this site.

  4. You could try this one, but without seeing the source I can only tell you it works for your example posted, and allows fee spacing between conditions (\s+)

     

    /24(?:h| h)\s+\d+°(?:C|F)\s+\d+\s+cm/i

     

    The website it's coming from is here: http://www.skinakiska.com/conditions/snow-report.aspx

    If that helps. Basically file_get_contents from that url put it into a var, then strip_tags, then do the preg_match.

     

    Some PHP Code:

    $page = file_get_contents(http://www.skinakiska.com/conditions/snow-report.aspx);
    $content = strip_tags($page);
    preg_match('/(24H|24 H).*?(\d+?)(cm| cm)/si', $content, $matches);
    print_r($matches);
    

     

    Should actually say that my expected output should be the number next to the cm, rather than what I said before. This RegEx is used for a bunch of different locations, so its put into a loop, but for now I just need this one to work. The difference between some of the other resorts is that they use 24 Hours, etc. which would just mean the first grouping would have 24 Hours|24H etc.

     

  5. We can only make a RegEx that matches your exact example.

     

    You'd have to give us specific rules to follow for a more accurate solution.

     

    Well basically I am just trying to get the number value before the centimeters (in this case 0) that appears directly after 24 h. The reasoning: We are getting snow reports for the last 24 hours and generally they are 24 h some characters, then 0 cm etc.

     

    So essentially I need the first occurrence of some number cm that appears after 24h or 24 h.

     

    In your example, you will get two different matches with the RegEx you've provided.

     

    Which is true, that's what I should expect, but I actually get no matches at all. I'm using preg_match to match and file_get_contents and strip_tags to alter the text before it hits preg_match, but I can't see those modifying the output to result in nothing when a test case on the same text, with 10 cm instead, results in proper matching.

  6. So I have a problem in which I have to get a webpage using file_get_contents, strip out the HTML then parse it with Regular Expressions to get the current snow conditions for that area.

     

    With my test cases, which are just copies of the text but with modified values of the amount of snow, it works. But when it goes to get the actual live value, which is currently 0 cm (hasn't changed so I don't know if it works on a different value), it returns a empty array. I have been looking across the web for the what could be causing this, and have try many different cases but nothing seems to work.

     

    The regex is:

    /(24H|24 H).*?(\d+?)(cm| cm)/si

     

    The text is:

    Nakiska Snow Report - Official Nakiska Ski Resort Snow Conditions var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-4125530-4']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();  snow report webcam weather mobile    Please enable javascripts to view this page properly // Snow Report Tickets & Passes Getting Here Trail Maps Photo Gallery Snow School Rental Equipment Childcare Events Calendar Hot Deals & Packages News News Archive Media Centre Contact EmploymentSite Map at_attach("menu_parent", "menu_child", "click", "y", "pointer");  Employment Contact Us Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com  BOOK YOUR VACATION ONLINE BELOW OR CALL 1-800-258-7669  View all packages      HOME > CONDITIONS > SNOW REPORT  NAKISKA SNOW REPORT  Saturday, October 29, 2011 2:02:10 PM Expected High Snow Runs Lifts Maximum 24 h 5°C  0 cm 4 2 New snow 24h 48h 7 Days YTD 0 cm 0 cm 0 cm 0 cm 0 in 0 in 0 in 0 in Snow Pack Upper Lower 50 cm 0 cm 20 in 0 in Weather High Low 5 °C 0 °C 41 °F 32 °F Snow Conditions Groomed Corduroy Groomed Trails 4 Run of the Day Mapmaker Activities & Events Great Opening Day with Excellent Skiing! Operation is from 10:00 AM until 3:30 PM Skiing and riding will be off the Gold Express on Upper and Middle Mapmaker , Big Bear and Morley Flats. Only Intermediate and Advanced terrain available Skiers and Riders will upload and download on Olympic Chair. We recommend only Intermediate and Advanced skiers and riders participate for this season weekend opener. RCR Ski More Card and Nakiska I Ski Card are Now on Sale!! Call 1 800 258 7669 to purchase yours and for further details The Monster Glades have been Expanded Winter Sports School Multi week programs are filling fast. Book today on line. Book your Winter Vacation with RCR reservations before November 30 and SAVE!!! Call 1-800-258-7669 to book your vacation! Calgary's Closest Mountain Resort. Only 45 minutes west of Calgary. Enjoy 2,555 vertical feet of the best Fall-Line Skiing in the Alberta Rockies! You can be riding while the rest are driving! Ski/Snowboard Nakiska this winter at Calgary's Closest Mountain Best Skiing Value in the Rockies! Additional Links - PDF Version of the Snow Report - Weather - Snow Conditions Defined  Follow us on facebook        Featured Photo Opening Day Turns    Conditions noted are current as of the time of the report and subject to change. Surface conditions will vary with skier use and weather. Ski and Ride at your own risk.  Home : Privacy Policy : Employment : Media : About Us : Contact : Site Map  Nakiska Mountain Resort (403) 591-7777 Toll Free: 1-800-258-7669 E-mail: information@skinakiska.com ©2010 All Rights Reserved. /* */ /* */

     

    My expected output:

    24 h 5°C  0 cm

     

    Any help would be appreciated.

  7. When you site gets amazing and you have more users than facebook saving that extra space and processing time to use a smallint(1) vs a varchar(3) is huge

     

    That is true. Actually I was trying to debate whether or not to use ID (int 255, auto-inc.) as a primary key in the Actions table as I am going to set up a cronjob to delete 2 day old actions. So the auto-incrementing ID would be used up eventually except it would take ALONG time I would imagine.

     

    But I couldn't think of a way around, any thoughts?

  8. If you have a properly built database advancing your queries to draw off multiple tables will drastically improve your abilities.

     

    Also I see you are using fulltext (Yes/No) instead of BOOL variables of (1/0)  Why???

     

    That sir is a good question.

    Well, helps me remember what its doing, BUT now that I think about it I could probably just put comments to remind me what I am doing.

  9. Try something like this:

     

    $friends = mysql_query(sprintf("SELECT * FROM `Friends` WHERE `Username`='%s' AND `Blocked`='No' AND `Mutual`='Yes'", mysql_real_escape_string($username)));
    
    while($r = mysql_fetch_array($friends)){
                $actions = mysql_query("SELECT * FROM `Actions` WHERE `Username`='{$r['Friend']}'");
    
    	       while ($recs = mysql_fetch_array($actions)){
    		     echo $recs['Username']."<br>";
    	       }
      }
    

     

    That seems to have worked. Thank you!

     

     

    You ever hear of a join query???

     

    Select  Friends.*, Actions.* 
    from `Friends` 
    Left join `Actions` ON (Actions.Username = Friends.Friend) 
    Where Friends.Username = '%s' and Friends.Blocked='No' and Friends.Mutual='Yes'
    GROUP BY Friends.Username
    

     

    Take it into phpmyadmin and play around with it

     

    Never have, I will look into that though. THANKS

  10. Good Morning/Afternoon (whichever applies)

     

    Okay, I am making a area on my website which users let each other know what they did. (Kinda like facebook's recent friend actions)

    Anyways, I ran into some problems. You see with the code I have to grab the friends that you have from one table, use them for another tables query to get the actions.

     

    So basically:

    Query Friends -> Use Friends to Query Actions -> Output Recent Actions

     

    The code I have is below

    $friends = mysql_query(sprintf("SELECT `Friend` FROM `Friends` WHERE `Username`='%s' AND `Blocked`='No' AND `Mutual`='Yes'", mysql_real_escape_string($username)));
    while ($friends = mysql_fetch_array($friends)){
                foreach ($friends as $fri){
              $actions = mysql_query("SELECT * FROM `Actions` WHERE `Username`='$fri'");
              $actionrows = mysql_num_rows($actions);
              for ($i=0;$i=$actionrows;$i++){
    	       while ($recs = mysql_fetch_array($actions)){
    		     echo $recs['Username'];
    	       }
              }
         }
           }
    

     

    The code just gives me a timeout error, but does output the $recs['Username'];

    It just takes forever to load it.

     

    I probably can achieve this some other way, I just don't know exactly where to turn. If you could show me a sign it would help~

     

    Regards,

    Jerzxu

  11. you store the data that makes up the picture as a string.  Well in reality, you'd be storing it as type blob.  Then you retrieve that string and make a loop to build it back up, pixel by pixel.

     

    edit:

     

    or well, I guess you could store it as a file. I mean, if you make a blob or longblob type column and use the target file as the value, that should work, too.

     

    Update: (Just some tidbits of info.)

     

    I was looking at a tutorial on how to insert images into a database and got it successfully running. Except I ran into some problems resizing it etc.

    I got frustrated and was about to go back to normal way just uploading etc. and realized this line of code when displaying an image from the database:

     

    header("content-type: text/jpeg");

     

    After some messing around with changing the file extensions etc. around I actually got my way of viewing to work.

     

    So now it will display a file with no file extension, or with a .somemadeupextension regardless. And the way I did it makes it quite difficult to copy without using printscreen.

     

    And that's all she wrote.

     

     

  12. you store the data that makes up the picture as a string.  Well in reality, you'd be storing it as type blob.  Then you retrieve that string and make a loop to build it back up, pixel by pixel.

     

    edit:

     

    or well, I guess you could store it as a file. I mean, if you make a blob or longblob type column and use the target file as the value, that should work, too.

    Okay, that makes sense.

    Thanks for the help

  13. if you have access to your cpanel you should be able to deal with hotlinking from there.

     

    an alternative is to store your pictures in a database and have a script retrieve the info and use the gd library to create and post a picture on the fly. 

    Posting a picture in a database. I was wondering about that actually. Does it actually post the picture itself into the database or just the link to the picture?

  14. I came up with an idea for stopping hotlinking, but I am not sure if it is possible.

     

    See with fileupload I devised the way of encrypting the filename so that it isn't possible to just randomly guess the image. (you could but it would be by extreme chance)

    Then it would move it with just that name and no extension so it isn't viewable. 

     

    Problem I ran into was that the browser doesn't know how to read the image seeing as it doesn't have an extension.

    Is there a possible way to make it so the web browser would know that it was an image using php codes, without making the files name also include a extension?

     

    Here's the basics of what's happening with the code:

     

    File upload -> Checks to see if its acceptable file type -> Generates a random number and adds it into the middle of the filename -> Encrypts new filename -> Moves to the images folder.

     

    So the file went from: image.jpg -> ima9328342734ge.jpg -> 8a5cd29fa948465792a084cff17a162e

     

    So in essence I am asking is it possible to make that file viewable without adding the extension onto the filename at the end?

  15. Just be mindful of session hijacking.  I see that you are storing the username in the $_SESSION['username'] variable.    Make sure that you are not providing information based on this value.. As to my knowledge it is easy enough for somebody to substitute this for another username if they have done prior research.  You might be ok, but it is just something to keep in mind :)

     

    http://www.damosworld.com

    How would you stop session hijacking then?

    Use cookies?

  16. session_start();
    include("connect.php");
    $username = $_POST['username'];
    $password = $_POST['password'];
    if ($_POST['username'] == "" || $_POST['password'] == ""){
    $_SESSION['Login'] = "None";
    header("Location: loginfail.php");
    } else {
    $password = md5($password);
    $query = sprintf("SELECT * FROM `Accounts` WHERE `Username`='%s' AND `Password`='%s'",
                        mysql_real_escape_string($username),
                        mysql_real_escape_string($password));
    $sql = mysql_query($query);
    //$sql = mysql_query("SELECT * FROM `Accounts` WHERE `Username`='$username' AND `Password`='$password'");
    if (mysql_num_rows($sql) == 0){
    	$_SESSION['Login'] = "Incorrect";
    	header("Location: loginfail.php");
    } else {
    	$sql2 = mysql_query("SELECT `Activated` FROM `Accounts` WHERE `Username`='$username'");
    	$active = mysql_result($sql2,0);
    	if ($active == "No") {
    		$_SESSION['Login'] = "UnAct";
    		header("Location: loginfail.php");
    	} else {
    		$_SESSION['Login'] = "Successful";
    		$_SESSION['username'] = $_POST['username'];
    		header("Location: code.php");
    	}
    }
    }

     

    Just reassuring, is that correct?

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