jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
New to PHP - How to implement php and keep html extension
jcbones replied to goofy78270's topic in PHP Coding Help
Sure, JS for the slideshow. -
New to PHP - How to implement php and keep html extension
jcbones replied to goofy78270's topic in PHP Coding Help
If you name all your pages with a php extension, the parser will go through that script. If it finds no PHP code, it will just return the file to the browser. In retrospect, it will slow the site down slightly, as it will take time for the parser to look at the file. I have a script that grabs all images from a directory, but it is made for something a little different. If you post your javascript code, I could put it in there for you. -
Sorting Array Decending by Element String Length
jcbones replied to natasha_thomas's topic in PHP Coding Help
Make sure this code block goes below the code that builds your array. function cmp($a, $b) { if (strlen($a) == strlen($b)) { return 0; } return (strlen($a) < strlen($b)) ? 1 : -1; } $a = $searchWords; usort($a, "cmp"); foreach ($a as $key => $value) { echo "$key: $value\n<br />"; } ?> -
I would contact the host, and tell them you have changed your code to abide by their policies. Yet, it still isn't sending mail. They can look in their error logs and see what the problem is.
-
Sorting Array Decending by Element String Length
jcbones replied to natasha_thomas's topic in PHP Coding Help
Which is exactly what I posted. Since I do not have your array names, I couldn't plug those in for you. I would be happy to though! -
Email programs are in serious need of some work. They don't seem to like CSS very much. I would try to use one of the universal colors suggested by W3.
-
Sorting Array Decending by Element String Length
jcbones replied to natasha_thomas's topic in PHP Coding Help
You thinking of something like: usort() [php <?php function cmp($a, $b) { if (strlen($a) == strlen($b)) { return 0; } return (strlen($a) < strlen($b)) ? 1 : -1; } $a = array('problomatical', 'notaproblic', 'notsomaticalanotam', 'no', 'template'); usort($a, "cmp"); foreach ($a as $key => $value) { echo "$key: $value\n<br />"; } ?> [/code] -
You need the file extension. You can then use mod-rewrite (.htaccess) to control the files that the server points an address to. Most all files I create are .php, I then create all of my links as .htm. I use mod-rewrite to take any address that ends in .htm and find the correct .php file for it. You could do the same for you situation, but right now, your server doesn't parse the PHP file, because it is set to only parse files that end in .php or .php5 Hope that helps.
-
mail will return false if the function fails. So, lets put a little de-bugging in there to see if it IS the SMTP server. if ($use_envsender) { if(!mail($mailto, $subject, $messageproper, $headers, $envsender )) echo 'Mail ran under 5 arguments has failed!'; } else { if(!mail($mailto, $subject, $messageproper, $headers )) echo 'Mail ran under 4 arguments has failed!'; } header( "Location: $thankyouurl" ); exit ; If you get one of the messages, it means PHP did NOT successfully send it to the email server. No message means that the server received it.
-
Make sure the From address is a valid address on your email server. You may have to create this address. GoDaddy will not send an email, if the from header is NOT a valid email address on their server. They like to be ambiguous on this point.
-
can you make an sql every X seconds with php?
jcbones replied to gibigbig's topic in PHP Coding Help
Yes. Depending on your server, you can use crontab to call a specific script, or command line. Or, you can use task manager. -
IP's can be spoofed. IP's change. Lots of reasons why IP isn't a good idea. If it were me, I would track it by a user ID, allowing only users to like or dislike. Yes, for each item a user likes, it would add a row to the database. You would need to think carefully about your indexes on this table, so that as it grew, you wouldn't have a serious bottleneck. I also think you could safely delete rows that are older than 6 months. Most topics don't stick around that long. Or, clean them when you archive the topic.
-
I don't see anything wrong with the way it is written. As far as tidying it up, just tab to keep the bracketed statements line up. <?php require("cfg.php"); //FOLDER PATH $dir_cat= $imgpath; $openDir_cat = opendir($dir_cat); while (false !== ($fileNames_cat = readdir($openDir_cat))) { $check_cat = $dir_cat. "/" . $fileNames_cat; $size_cat = @getimagesize($check_cat); // this check mime of file if($fileNames == "." || $fileNames_cat == ".." || strpos($size_cat[mime], "image") === FALSE) { continue; // exclude everything wha is not image } else { $imagesAll_cat[] = $fileNames_cat; // create an array of images } } $imgnr_cat=0; //COUNT THE NUMBER OF FILES IN THE UPLOAD DIR. $imgct_cat=count(glob($dir_cat . "*")); echo '<center><fieldset class=fieldset>' .'<legend> IMGS ' .' (' .$imgct_cat. ' IMAGES)</legend><div>'; //GET IMAGES AND DISPLAY THEM while ($imgnr_cat<$imgct_cat) { echo '<a href=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>' .'<img width=140 height=100 src=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>' .'</a>'; $imgnr_cat++; } echo '</div></fieldset></center>'; ?>
-
You could use the PHP constant. "Your IP: ".$_SERVER['REMOTE_ADDR'].PHP_EOL
-
You mean like on page 1 of the tutorial where it says> include('dbcon.php'); Database connection is a requirement, most tutorials don't spell it out. This one doesn't, but shows the file included.
-
NO, running strip slashes after mysql_real_escape_string() will defeat the purpose of the function. htmlentities is for displaying user data to a page. I test for expected data type, strip out anything not allowed, then pass it through mysql_real_escape_string. For instance, if I expect the user to pass a number. $number = (isset($_POST['number'])) ? intval(strip_tags($_POST['number'])) : 0; $sql = sprintf("SELECT * FROM table WHERE id = %d",mysql_real_escape_string($number));
-
It is hard to write a query, when you don't know the database tables, or how you know what story you are posting. $sql = "SELECT a.*,b.* FROM story AS a JOIN user AS b ON a.userid = b.userid WHERE storyid = '$id'"; You shouldn't need to know what the userid is. The story table knows what the userid is, since it should be stored in a column. Just join that column to the userid column in the user table, MySQL will do the rest.
-
While you are trying to give us some more information. TOP OF SCRIPT ini_set ('display_errors', 1); error_reporting (E_ALL); EDIT, don't nest while loops of MySQL data. Pull everything you want with a JOIN query. Otherwise, you are liable to run into problems.
-
So, it doesn't work, and you are sure it isn't a coding problem! The next step I would suggest is to stab the server with an ice-pick. Maybe you can get the little troll living inside that is stopping your script from executing properly.
-
OK, here you go. Gold should be handled by the server. I put it in the script just to show some gold on the page. It will not increment, it will just display 100. You should let the database handle the gold. Timer runs on server time, and displays the message you want. Until it gets to 1 minute, then it starts a countdown in seconds. Page refreshes on time hitting 0. <?php //session_start(); $gold = 100; //this amount should be handled and stored in the database. Retrieved each time by the database. //MODIFICATION BELOW THIS LINE IS NOT REQUIRED $date = date('i'); $sec = date('s'); $diff = ($date < 30) ? 1800 - (($date * 60) + $sec) : 3600 - (($date * 60) + $sec); //set diff to run split on the half hour. $hld_diff = $diff; /* if(isset($_SESSION['ts'])) { //if timestamp is active in session $slice = ($timestamp - $_SESSION['ts']); //get the difference between the timestamps. $diff = $diff - $slice; //subtract the diff from the ts. } if(!isset($_SESSION['ts']) || $diff > $hld_diff || $diff < 0) { $diff = $hld_diff; $_SESSION['ts'] = $timestamp; } */ //Below is demonstration of output. Seconds could be passed to Javascript. $diff; //$diff holds seconds less than 3600 (1 hour); $hours = floor($diff / 3600) . ' : '; $diff = $diff % 3600; $minutes = floor($diff / 60) . ' : '; $diff = $diff % 60; $seconds = $diff; ?> <div id="strclock" style="display:none">Clock Here!</div> <div id="clock">Message Here</div> <script type="text/javascript"> var hour = <?php echo floor($hours); ?>; var min = <?php echo floor($minutes); ?>; var sec = <?php echo floor($seconds); ?> function checkTime() { var time = document.getElementById('strclock').innerHTML; if(time == '00:00:00') { window.location.reload(true); } } function countdown() { if(sec <= 0 && min > 0) { sec = 59; min -= 1; } else if(min <= 0 && sec <= 0) { min = 0; sec = 0; } else { sec -= 1; } if(min <= 0 && hour > 0) { min = 59; hour -= 1; } var pat = /^[0-9]{1}$/; secs = (pat.test(sec) == true) ? '0'+sec : sec; mins = (pat.test(min) == true) ? '0'+min : min; hours = (pat.test(hour) == true) ? '0'+hour : hour; document.getElementById('strclock').innerHTML = hours+":"+mins+":"+secs; if(min >= 1) { document.getElementById('clock').innerHTML = min+1+' minutes until gold deposit!'; } else { document.getElementById('clock').innerHTML = sec+' seconds until gold deposit!'; } checkTime(); setTimeout("countdown()",1000); } countdown(); </script> <table border="1"> <tr><th>GOLD</th></tr> <tr><td><?php echo $gold; ?></td></tr> </table>
-
Sorry, without more info, that is all I can give you.
-
Look Here