PHP - Random Text Load Script
Hi,
I am wanting to create a random fact script for a small website project. The idea is when the user loads a page a random fact will appear at the top ( I guess from an array of strings I will make?) Can anyone recommend the most efficient and easiest way to go about this please? Similar TutorialsHello, I have been using a random text script to display a useful tip to the user when they land on a certain page. This is how the script looks: Code: [Select] <?php $random_text = array("This is an example tip", "This is another example of a tip", "And another...", "And one more"); $sizeof = count($random_text); $random = (rand()%$sizeof); print("$random_text[$random]"); ?> At the moment the tip will display randomly everytime the page is loaded. Is there any way I can add a small button that says "Give me another" or something, so that when they click it another random fact will come out? If possible I would like to avoid them having to reload the page everytime. Any help is greatly appreciated. i have got this script which displays all folders within a folder but what i want to do now is get it to display a random picture for each of the folders that it is showing in the grid. i know how to display a random image using array_rand() but i don't know how i would implement it. Code: [Select] <form name="Gallery" method="post"> <?php $path = "gallery_files/gallery/"; $dir_handle = @opendir($path) or die("Unable to open folder"); echo "<table cellspacing='15'>"; echo "<tr>"; while (false !== ($folder = readdir($dir_handle))) { if($folder == "pictures.php") continue; if($folder == ".") continue; if($folder == "..") continue; echo ($x % 6 == 0) ? "</tr><tr>" : ""; echo "<td><a href='pictures/?folder=$folder'><img src='path/to/random/image' style='height:auto;width:110px;' alt='$folder'></a><br /><a href='pictures/?folder=$folder'>$folder</a></td>"; $x++; } echo "</tr>"; echo "</table>"; closedir($dir_handle); ?> </form> hi everyone i've just finnished a lynda.com course and began coding my own site.. i want to be able to put the script it self in the database. Then from read and execute the script from content.php BUT i get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\content.php(35) : eval()'d code on line 1 Call Stack so far it's has been fairly easy to correct the errors, but this one i don't know how to handle.. can anyone give me a hint where I've mistaken The script i put in the database if (!isset($_GET['category'])) { $query = "SELECT * FROM links ORDER BY category ASC"; $result = mysql_query($query); echo "<table border=\"0\" width=\"100%\"> <tr> <td> <ul>"; while ($row = mysql_fetch_assoc($result)) { echo "<li><a href=\"links.php?content=links&category=" . $row['category'] . "\">" . $row['category'] . "</a></li>"; } echo "</ul> </td> </tr> </table>"; } if (isset($_GET['category'])) { $linkcat = $_GET['category']; $query = "SELECT * FROM links WHERE category='{$linkcat}' ORDER BY title ASC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<table border=\"0\" width=\"100%\" height=\"160\"> <tr> <td colspan=\"3\" align=\"center\" valign=\"top\"> <h1><a href=\"" . $row['address'] . "\">" . $row['title'] . "</a></h1> </td> </tr> <tr> <td colspan=\"3\" align=\"center\" valign=\"middle\"> <p>" . $row['description'] . "</p> </td> </tr> <tr> <td align=\"left\" valign=\"bottom\" style=\"float:right\"><a href=\"profile.php?username=" . $row['author'] . "\">" . $row['author'] . "</a></td> <td align=\"center\" valign=\"bottom\"><p>" . $row['votes'] . "</p></td> <td align=\"right\" valign=\"bottom\" style=\"margin-right:10;\"><p>" . $row['clicks'] . "</p></td> </tr> </table> <br /> <hr /> <br />"; } } content.php <?php require_once('includes/connection.php'); ?> <?php $content = $_GET['content']; $query = "SELECT * FROM pages WHERE page_name='{$content}'"; $result = mysql_query($query); if (!$result) { echo "Could not successfully run query from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } $row = mysql_fetch_assoc($result); $str = $row['content']; eval("\$str = \"$str\";"); echo $str; ?> Thank you in advance Dokter G The following code does what I want it to, but after it's done doing it, it won't stop loading. I believe it is because of the while loops (while(1) { ... } and while($data = ...) { ... }). I need while($data = ...) to read the data from the fsockopen. Thanks in advance function ircConnect($server, $port, $channel, $nick, $pass, $name, $msg) { set_time_limit(15); //If we put set_time_limit(0), the page won't timeout and never stops loading (The script works, that I'm aware of) $fp = fsockopen($server, $port); if(!$fp) die($php_errormsg); if(empty($php_errormsg)) { $error = "None!"; } else { $error = $php_errormsg; } echo "<table border='1' bordercolor='#FFCC00' style='background-color:#FFFFCC' width='400' cellpadding='3' cellspacing='3'>"; echo "<tr><td>Server</td><td>Port</td><td>Channel</td><td>Nick</td><td>Password</td><td>Error</td></tr>"; echo "<tr><td>$server</td><td>$port</td><td>$channel</td><td>$nick</td><td>$pass</td><td>$error</td></tr>"; echo "</table>"; fputs($fp, "USER aBot testchan.org TestchanIRCBot :TheBot\n"); fputs($fp, "PASS $pass\n"); fputs($fp, "NICK $nick\n"); fputs($fp, "JOIN $channel\n"); fputs($fp, "PRIVMSG $channel :$msg, my name is $nick!\n"); while($data = fgets($fp, 128)) { $ex = explode(' ', $data); echo nl2br($data); flush(); if($ex[0] == "PING") fputs($fp, "PONG " . $ex[1] ."\n"); } } http://i.imgur.com/E6j79.jpg Hello there, I have a script which uses the LOAD DATA LOCAL INFILE command see below: <?php //connect to your database mysql_connect("localhost", "xxx", "xxx"); //(host, username, password) //specify database mysql_select_db("xxx") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "LOAD DATA INFILE '/public_html/admin/files/test-jp-stock.csv' INTO TABLE 'jpaero_stocksearch' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; if(mysql_query($query)){ echo ">> New Stock Data has now been uploaded. Database is now live and searchable.";} else{ echo "Upload failed. Please contact support.";} ?> Initially I uploaded the csv file through phpmyadmin and everything worked fine - so I then used the SQL generated inside my script, changing the location to where the file actually is - however now nothing happens at all. Any ideas on whats gone wrong, gratefully received! Thanks, Not sure where to put this, so I figured this would be a good place to start.
First:
I host a website for a client through iPage.com called Authentic Log Houses at authenticloghouses.com.
This website uses a wordpress platform.
Anyway, on with the issue. My client called me one day and said a text ad showed up on his navigation menu of the website selling viagra! Immediately the worst case scenario went through my mind. I told him I'd check it out as soon as I could. I got home and checked his website using Chrome (my preferred browser) only to find it exactly as it should be (with no ad). I assumed at that point that he was probably the only one that could see the link and was probably just dealing with a virus or malware that was affecting his browser.
I told him he should run an antivirus or malware removal program and see if he still saw the ad. He did, but found nothing. He then called his brother and asked him to view his website to see if the ad appeared. It did. I checked again on my computer, still nothing. Finally I decided to try a different browser than Chrome and found that Firefox, IE, Safari, and Opera ALL show the ad!
I still don't know why every browser except Chrome shows the ad, but now that I could duplicate the issue, I eliminated the possibility of a virus or malware since multiple computers showed the same ad (which changes from time to time). I viewed the source code to see where it may have been coming from and it simply showed an anchor tag with a link to a random website in the main nav menu outside the un-ordered list that the website uses, however, I cannot find that link in the source files.
I spoke with iPage's technical support to see if they had any ideas and they said to update all my plugins and install the "Link Removal Tool" and enter the linked url. They said this tool has helped many people and works really well. Nothing worked for me. I even tried their "Pro" version (which is still free o_O) and it seemed to be nothing but spam, so now I don't trust them in the least.
The current text ad can be view on the website in green in the top navigation bar saying "Payday loans direct lender no teletrack" and links to a 404 at worldwiderssfeedcompendium.com.
I'm currently out of ideas! Any help would be awesome. I've never seen this before! I can upload any files if necessary.
Thanks in advance,
Kevin
Hi Guys, I wonder if you can help me before I go crazy? I have the task of updating a site by adding text to every page, at the moment there are three pages on the live website that show both images and text, I am to update the remaining 6 with text to go with the images.... I thought this was all fine and dandy, added the text in, checked the code, uploaded to the FTP site and nothing, only 1 page worked. I am stuck as I have used the same method to add text to all the pages yet those elusive pages refuse to show text! This is driving me crazy and i am hoping that one of you guys has come across this before and will be able to highlight a missing piece of code or have a solution? I do appreciate your time and any suggestions that you have. I have attached the page below. Thanks guys! This is a section of my code that goes and gets videos from any video site. What I’m having issues with is having it post a random title, that are all in a text file called titles.txt. What I’m wanting to accomplish is have my script go pull the video embed code, the duration, the tags, etc. Which all works fine until I get to the title part where it pulls locally from the server from the text file. I'm not an advance programmer so not sure if I am even approaching this correct way. Here is the code I have that is responsible for putting the title in. I appreciate your help. $video = array( ‘user_id’ => $this->user_id, ‘status’ => $this->status, ‘site’ => ‘my site’, ‘id’ => ‘’, ‘embeddable’ => true, ‘url’ => ‘’, ‘titles’ => ‘’, ‘title’ => ‘’, ‘description’ => ‘’, ‘tags’ => ‘’, ‘category’ => ‘’, ‘thumbs’ => array(), ‘duration’ => 0, ‘embed’ => ‘’ ); function random_title () { $titles = file (“titles.txt”, FILE_IGNORE_NEW_LINES); $num = rand (0, intval (count ($titles) / 3)) * 3; return ucwords($titles[$num]); } //Title if(preg_match(’/title="(.*?)"/’, $match, $matches_title)) { $video[‘title’] = random_title(). ’ - My site name’; } else { $this->errors[] = ‘Failed to get video title for ‘.$video[‘url’].’!’; if (!$this->debug) continue; else $debug_e[] = ‘TITLE’; }
I have a site that I have an about page with pictures of people on it. I would like to create something that would do the following: * When you click on one of the images, i need text for that image to load in a text area. I would like to do this rather than have to make a different HTML page for each person, but I am not sure how to go about doing it. I do not have a database for this site, so I will need to pull the text from a text file or something like that. Any ideas on how to get started would be helpful. Thanks in advance! Hi,
In reference to my first attached image, I have a form which displays two SELECT/drop-down fields (labeled "Store Name" and "Item Description".....and both of which pull-in values from two separate lookup/master tables, in addition to providing an additional option each for "NEW STORE" and "NEW ITEM").
Now, when first-run, and/or if "NEW STORE" and "NEW ITEM" are not selected from the drop-down's then the two fields in green ("New Store Name" and "New Item Name" are hidden, by means of the following code:
<div class="new-store-container" id="new-store-container" name="new-store-container" style="display:none;"> <div class="control-group"> <div class="other-store" id="new_store_name"> <?php echo standardInputField('New Store Name', 'new_store_name', '', $errors); ?> </div> </div> </div>Conversely, if "NEW STORE" and/or "NEW ITEM" are selected from the two drop-down's then one (or both) of the "New Name" fields are unhidden by means of the following two pieces of code, one PHP and the second JS: <select class="store-name" name="store_id" id="store_id" onclick="toggle_visibility('store_id','new-store-container')"> <?php echo $store_options; ?> <?php if($values['store_id'] == "OTH") { echo "<option value='OTH' selected> <<<--- NEW STORE --->>> </option>"; } else { echo '<OPTION VALUE="OTH"> <<<--- NEW STORE --->>> </OPTION>'; } ?> </select> function toggle_visibility(fieldName, containerName) { var e = document.getElementById(fieldName); var g = document.getElementById(containerName); if (e.value == 'OTH') { if(g.style.display == 'none') g.style.display = 'block'; else g.style.display = 'none'; } }All of that is working just fine. The problem I'm having is that when I click the "Create" button, after having left any one of the form fields blank, the two "New Name" fields are hidden again, which I don't want to happen i.e. I want them to remain visible (since the values of "store_id" and/or "item_id" are "OTH"), so that the user can enter values into one or both of them, without havng to click on the drop-down a second time in order to execute the "on-click" code. The second attached image shows how the fields are hidden, after clicking "Create". How can I achieve that? It would be greate if someone could cobble-up the required code and provide it to me, since I'm relatively new to this. Thanks much. Snap1.png 26.14KB 0 downloads Snap2.png 149.47KB 0 downloads I'm having a problem and need an answer to why its happening and how to prevent it. Scenario: I begin load my home page which starts with a session_start(); .... Before it FULLY completes loading I try to navigate to another page and BOOM, that page will not load and any other page that begins with session_start(); will not load unless I close and restart the entire browser or wait about 10 minutes.... I will note my website makes ajax calls every 5 seconds or so, but I use setTimeout for them. Any help??? Thanks ahead! As above, I have a lottery style site that picks a random number between 1-8 but my users complain for some reason that this is not enough. So i was told to look into using fopen and random.org to generate a random number. Anyone have experience of this and perhaps a code snippet for me to look at and possibly use? help will be appreciated. So its a virtual pet script I'm making. This script changes the image of the pet with time. It also puts the user's name,in text on the image. For some reason It doesnt turn out too well= http://amiteka.comli.com/viewpet_forum.php?id=1 Can someone tell me what is wrong with the script or how I can make it show something like; Error on line # <?php require_once('./inc/config.php'); function greaterDate($dformat, $beginDate, $endDate) { $subtract = $endDate - $beginDate; if($subtract > 0) { return 1; } else { return 0; } } function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row [petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row [adopter]}'"); $usercc = mysql_fetch_array($results2); if(greaterDate(".", $row[fulldate], date('Ymd')) > 0) { $im = showpet_forum($pet[adulturl]); $image = imagecreatefrompng($im); return imagepng($image); header('Content-type: image/png'); } elseif(greaterDate(".", $row[halfdate], date('Ymd')) > 0 && greaterDate (".", $row[fulldate], date('Ymd')) <= 0){ $im = showpet_forum($pet[teenurl]); $image = imagecreatefrompng($im); return imagepng($image); header('Content-type: image/png'); } elseif(greaterDate(".", $row[halfdate], date('Ymd')) <= 0){ $im = showpet_forum($pet[babyurl]); $image = imagecreatefrompng($im); return imagepng($image); } } } echo check(); ?> Thank you for any help. Hello. I have one programming problem. I have this log, from witch i have to read specific area of text: webtopay.log OK 123.456.7.89 [2012-03-15 09:09:59 -0400] v1.5: MIKRO to:"1398", from:"865458961", id:"13525948", sms:"MCLADM thing" So i need the script to extract word "thing" from that log. Also that script has to check if there is new entries in the log, and extract text from the last one. (Explaining in other words, that script should extract word AFTER MCLADM. Every time its a different word) p.s. I need that script to be integrated here (this has to send command to server "/manuadd (text from log)" : Code: [Select] <?php try{ $HOST = "178.16.35.196"; //the ip of the bukkit server $password = "MCLietuva"; //Can't touch this: $sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("error: could not create socket\n"); $succ = socket_connect($sock, $HOST, 4445) or die("error: could not connect to host\n"); //Authentification socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1) or die("error: failed to write to socket\n"); //Begin custom code here. socket_write($sock, $command = "/Command/ExecuteConsoleCommandAndReturn-SimpleBroadCast:broadcast lol;", strlen($command) + 1) //Writing text/command we want to send to the server or die("error: failed to write to socket\n"); sleep(2); // This is example code and here has to be that script i want to make. //while(($returnedString = socket_read($sock,50000))!= ""){ $returnedString = socket_read($sock,50000,PHP_NORMAL_READ); print($returnedString) //} print("End of script"); socket_close($sock); }catch(Exception $e){ echo $e->getMessage(); } ?> I hope i made things clear and you will help me Thanks I have a php script that I am trying to run ( I dindt write it) but the index.php file loads basically all of the php file in plain text instead of running it. Any sugguestions? PHP is isntalled since other php scripts work.
Thanks
Hi there, Im working on my little project and I would appreciate your help. I have only basic knowledge of php, mostly I just copy some scripts that could be useful for me. Im trying to find some simple script that allows me to see the written text on web page no. 1 on webpage no. 2.. Something like send the form to email, except I dont want to send it on email, but different webpage. Something like different way of eshop, where you get your order shipped to email, but I wanna send this information to webpage. Is there such a script like Im describing? Probably is but I dont know how to search for this..
Thank You
Edited by Radim, 21 October 2014 - 07:15 AM. This is the php file code to a video jukebox add-on script, for a popular web video script. I'd like to modify it so the "Click Here" text font and color can be changed. Can you help or suggest what I can do to accomplish this? Thanks Code: [Select] <?php include("../classes/config.php");?> <artworkinfo> <? $query = "select * from videos where viewtime<>'0000-00-00 00:00:00' and public_private='public' AND approved ='yes' AND promoted ='yes' limit 10"; // Max 10!"; $db=mysql_connect ($dbhost,$dbusername,$dbpassword) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($dbname); $num_rows = mysql_num_rows(mysql_query("select * from videos WHERE public_private = 'public' AND promoted = 'yes' AND approved ='yes'")); $result = mysql_query($query) or die ('Query Error: ' . mysql_error()); while ($results = mysql_fetch_array($result)) { ?> <albuminfo> <artLocation>../uploading/thumbs/<?=$results['video_id']; ?>.jpg</artLocation> <artist>Click Here!!</artist> <albumName><?=$results['title']; ?></albumName> <artistLink>../play.php?vid=<?=$results['indexer']; ?>&src=jukebox</artistLink> <albumLink>../play.php?vid=<?=$results['indexer']; ?>&src=jukebox</albumLink> </albuminfo> <? } mysql_close(); ?> </artworkinfo> I am looking for a dynamic image script that handles word wrapping and possible font resizing. Basically, I have a dimensions, a font and a company name. So, lets say I am trying to make a 300x300 image for Bob's Boats in verdana. I want a script that not only creates the image, but tries to use up the available space (putting each word on a line, using a large font, horizontally and vertically aligning everything) Worst case I'll write my own, but the algorithm seems pretty complex. For example, lets say the companies name was: Chocolates in a Basket, it could be: Chocolates in a Basket Or: Chocolates in a Basket But never: Chocolates in a Basket Worst case, I might make it so that it supports 3 lines, but only ever puts the company name on 2 by default, and if the user wants to manually change it, they can. Even that isn't perfect though, because if the dimensions are something like 300x35, you wouldn't want a second line, let alone a 3rd. |