laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
Enable the session support in php.ini
-
Disable Certain PHP Functions For a Specific Directory?
laffin replied to User149's topic in PHP Coding Help
Acutally i found this tidbit here That with the apache Directory option should get u what u want -
Disable Certain PHP Functions For a Specific Directory?
laffin replied to User149's topic in PHP Coding Help
From what I can gather this is only possible with the cgi version of php not the apache module. http://www.askapache.com/php/custom-phpini-tips-and-tricks.html -
<?php $name='[Kira-Fansub]_HIGHSCHOOL_OF_THE_DEAD_-_04_(BD_1920x1080_x264_AAC) [F0E73009].mkv'; $str=preg_replace(array('/(\s*?[\[(].*?[\])]\s*?)/','/(-.*)/','/(_)/','/( )/'),array('','',' ',' '),$name); echo $str; ?> output How it works: 1st match ('/(\s*?[\[(].*?[\])]\s*?)/') catches [] and () items and removes them ('') 2nd match ('/(-.*)/') drops everything after the dash, including the dash ('') 3rd match (/(_)/) replaces underscores with spaces (' ') 4th match (/( )/) Double spaces replaced with single space (' '):
-
<?php $data=<<<EOF 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 12345678 1234567890 1234 12 EOF; function numfmt($val) { return "0x". substr(str_repeat('0',.$val[0],-; } echo preg_replace_callback('/\b[\da-fA-F]{1,8}\b/','numfmt',$data); in the 4 test case. 1) was had 8 hex digits (max digit length) so 0x was prefixed 2) had 10 hex digits (exceeds digit length) so was skipped) 3 & 4) didnt have enough hex digits so both were padded with 0's
-
Actually i encountered a similar problem awhile back, the problem is more on the image app they are using to save the image. I found some image apps did not work correctly with the gd functions while others did. An option u may have open, is to use imagemagick or netpbm to do the conversions for u, if you have these packages available to your server as well as system function in your php configuration. the other option is switch image app and testing which apps work with gd correctly. from there its just a matter of resaving the image with the ones u found to work.
-
but caching u would require some shared memory resources otherwise your back to file caching. But the OP question was very vague, than he elaborates what he's trying to attempt in his last post. and by his posts, there is no real concept of what file functions do. and how do throtthle bandwidth. 1) learn to code 2) Post code yer having probs with otherwise this thread will just be forgotten in a few days
-
I think he's trying to scrape the page with the info from the tables. the problem I seen was that the final 2 columns (countdown and aittime) are done via a javascript.
-
no real reason to use fread in that situation. prolly readfile is a better solution. bout hard part is determining mime type for the browser to handle php.net has several examples of this: http://php.net/manual/en/function.readfile.php
-
Thing u must know about sessions: session_start must be called before any output is sent, this includes error messages from php. file1.php <?php session_start(); $_SESSION['msg']='Hello World!'; header('Location: file2.php'); ?> file2:php <?php session_start(); echo '<h1>'. $_SESSION['msg'] ."</h1>'; its a trivial example. as u can see i don't pass msg with any method but using a session variable.
-
I think u have a misconception of how include works. as I see multiple includes of the same file all over. include inserts file at that position. so the included file already has access to the global variables from the main file. file1.php <?php $var=10; include('file2.php'); echo $var; ?> file2.php <?php $var=$var+25; ?> in effect file1.php becomes <?php $var=10; $var=$var+25; echo $var; ?> I also don't see any $_POST/$_GET processing
-
Really don't see the need for an iframe. But if yer already using sessions. store the uid,pid in the session, which the uid should be set in the login page processing portion.
-
The image tag generator only had a few commands image - Select a background image font - Select font color - Set Background foreground color coord - Set X,Y Coordinates text - write on image with text u had opportunity to have custom variables: username, url, email, posts, rank, etc..... it was more of a system to allow users a unique sig in the forums. but it was found useful in other sections of the site to display statistics and such. But it still the same concept of a template system. Since I didnt want users direct access to GD/PHP functions, and for many programming php code to display a simple tag like this was way over their heads, and many which have no coding experience. It's been a number of years since i wrote that code.... (Just for nostalgia i pulled out the code to look at the script). U can find a lot of similarities of systems when it comes to templating. Templating just sets forth a standard of doing something. U set the page layout, and tags for content. allow the core engine to the rest. Twig, sumone else brought up. Even tho that the concept is nice, I dont see a need for it. Your OP was on how to build one, Thats the reason I posted a link to a templating system that was more PHP specific, being somthing like 50 lines of code, makes it easy to understand. And gives you some idea about using cache systems. The article is more of a guide.
-
U do know that just a general question will get u a variety of answers. No, it will work on a stream of bytes (a byte has 8 bits) Without a detail explanation, or code snippets your questions are vague and generalized, so u will get answers based on what ppl assume you want. that all really depends what yer operations are on your data if yer doing a simple bitflags system, than u dont need a whole lot just Get/Set/Clear/Toggle Bit functions. if your were say encrypting than u need to convert the stream into char/ints. But all these really needs a clear explanation of what yer trying to accomplish
-
No the tags were like XBox Gamer tags.
-
Well I made some template systems before, and the major reason to make these systems is to allow users access to some variables and functions. So it allows any user to be able to design content without knowledge of php or coding. I think my first one was for a image tag generator, which allowed users to change background images, choose a font, and write text with some of their user infomation as variables. But I totally agree with your statements. template systems should make display easier for the end user. So providing a completely new scripting language is rather pointless, as the end user would have to learn a new language.
-
<?php $str="Hello there 1 2 3 4 5"; preg_match_all('/((?:[a-z]\w*\s?)+|(?:\d+))(?:\s+|$)/i',$str,$matches); print_r($matches); I got this for the output ( [0] => Array ( [0] => Hello there [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 ) [1] => Array ( [0] => Hello there [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 ) )
-
I really dont see the need to re-read the db to update the session variable. when u can do it in your processing script. $avatar=isset($_POST['avatar'])?trim($_POST['avatar']):NULL if(!empty($avatar) && $avatar!=$_SESSION['avatar']) { $update[]='avatar=\''. mysql_real_escape_string($avatar). '\''; $_SESSION['avatar']=$avatar; } . . . if(!empty($update)) { $sql='UPDATE users SET '. implode(',',$update) ." WHERE id=$userid"; mysql_query($sql); } however this is just a simple example
-
Templating systems are only really useful when you have a group, and dont want them to have access to php functionality. But if its a project for yourself, than yeah, php will be a better choice as a templating system. A nice example would be here: Template Engines its pretty dated, as the template they use as an example uses: <?=$var;?> since than php has gone to the use full tags, as common practice: <?php echo $var; ?>
-
Protecting Against SQL Injection But Still Providing Flexibility
laffin replied to chaseman's topic in PHP Coding Help
<?php $message=<<<EOF --- | | ----- ( o.o) |~| ''' </pre><script>alert('XSS');</script><pre> EOF; ?> <pre> <?php echo htmlspecialchars($message); ?> ?> </pre> htmlspecialchars is a useful function when u want to display things. -
Protecting Against SQL Injection But Still Providing Flexibility
laffin replied to chaseman's topic in PHP Coding Help
What u are referring to is not SQL injecttion but XSS attack. given your example, if u use echo "<pre>$message</pre>"; what prevents a user into putting this into the message --- | | ----- ( o.o) |~| ''' </pre><script>alert('XSS');</script><pre> Oh, no... now that I know yer system is XSS exploitable. I can create a javascript function to say get user information, and send it to my server. Rule #1) Don't trust user input -
I think wordpress wud be too overwhelming for a beginner. wuts hard to believe is: I can figure out how to link up a page to a database, draw the most recent story, and display the first 100 words. I just can't figure out how to make a "Read More" function where it will link to a different page that has the whole story. Usually these Read More pages have a number of headlines and stories Headline 1... Read More Headline 2... Read More Headline 3... Read More and all a read more is a single page which uses a parameter in the uri http://my.site.com/readstory.php?id=xxx the readstory.php would use $_GET for the story id and display that one story. if you want examples, try a site such as http://www.hotscripts.com there are plenty of sites that have simpler systems than wordpress.
-
Without any actual code, your gonna get 100 different ways ppl think it should be done X[0,1,2] = [Link, Cloud, Cloud, Mario, Mario, Luigi] Y[0,1,2] = [Zelda, Barrett, Tifa, Luigi, Bowser, Mario] Topcats code is closer to what I think u want, andy-h's code strips out the 1 - 1 match you have going. in topcats' code u can replace this block if(!array_key_exists($x[$i], $z)){ $z[$x[$i]]= array($y[$i]); }else{ $z[$x[$i]][] = $y[$i]; } with just this $z[$x[$i]][] = $y[$i];
-
Like I said the code works, check your php error logs
-
Send results back to your form, u can use $_GET <?php $username=isset($_GET['uname'])?$_GET['uname']:''; ?> <form action="form_action.php" method="post"> User name: <input type="text" name="uname" /><br /> <input type="submit" value="Submit" /> </form> in your process form <?php $uname=issset($_POST['uname'])?$_POST['uname']:''; if(!is_valid($uname)) header('Location: form.php?uname='.urlencode($uname)) well that should give u an idea of a pure php solution, but i would never send the password using this method (have them re-enter it) Note: Me & Blue posted about the same time. His Solution is based on an all in one form/processing script. The solution i presented here is for seperate form/processing. Both will work, just depends which system you implement.