PHP - (beginner) Defining A String In A Separate File...
$poststart = "<!-- Begin -->";
$poststop = "<!-- End -->";
$parsedpost1 = explode($poststart, $contenu);
$parsedpost2 = explode($poststop, $parsedpost1[1]);
$contenu = $parsedpost1[0] . $poststart . $newpost . $poststop . $parsedpost2[1];
The above code will set 2 markers and replace whatever inside by $newpost, which is defined elsewhere in the page. But what if $newpost is so long that I'd be more comfortable storing it in a separate file?
How would I go about calling said file on that last line? (I'm referring to the specific syntax.)
Thx
Similar TutorialsWhat is the most secure way? Having DB connect script in the beginning of every script you need db for, or Having a database.php script containing the script and then including it to all other php. How to do it? I have read some methods but they seem to not work. This is what I have got so far:
<?php Hi, When the user creates a contact, then edits the contact that final edited information is shown in a file called "my data.txt". After this, when I select my php file "save_contact_details.php" the details stored in the text file "my data.txt" are not retrieved. How can I retrieve them? At the moment the issue I'm having is that I see no data when I click on "save_contact_details.php" after I filled in all the contact persons information. Feel free to watch this video I recorded to help you understand what I am talking about. https://streamable.com/rbw6p save_contact_details.php code <html> <body> <?php $myFile=fopen("mydata.txt","r") or exit("Can’t open file!"); // Write each line of text into the text file file fwrite($myFile, $_POST["lastname"]."\r\n"); fwrite($myFile, $_POST["firstname"]."\r\n"); fwrite($myFile, $_POST["address01"]."\r\n"); fwrite($myFile, $_POST["address02"]."\r\n"); fwrite($myFile, $_POST["town"]."\r\n"); fwrite($myFile, $_POST["postcode"]."\r\n"); fwrite($myFile, $_POST["telephone"]."\r\n"); fwrite($myFile, $_POST["email"]."\r\n"); fclose($myFile); ?> <h1>My Contact Details</h1> <p>The contact details that you have submitted are shown below:</p> <table> <tr> <td align="right">Last name: </td> <td><?php echo $_POST["lastname"]; ?></td> </tr> <tr> <td align="right">First name: </td> <td><?php echo $_POST["firstname"]; ?></td> </tr> <tr> <td align="right">Address 01: </td> <td><?php echo $_POST["address01"]; ?></td> </tr> <tr> <td align="right">Address 02: </td> <td><?php echo $_POST["address02"]; ?></td> </tr> <tr> <td align="right">Town / city: </td> <td><?php echo $_POST["town"]; ?></td> </tr> <tr> <td align="right">Post code: </td> <td><?php echo $_POST["postcode"]; ?></td> </tr> <tr> <td align="right">Telephone: </td> <td><?php echo $_POST["telephone"]; ?></td> </tr> <tr> <td align="right">E-mail: </td> <td><?php echo $_POST["email"]; ?></td> </tr> </table> </body> </html>
<html> <body> <?php $myFile=fopen("mydata.txt","r") or exit("Can’t open file!"); // read each line of text from the text file $lastname = fgets($myFile); $firstname = fgets($myFile); $address01 = fgets($myFile); $address02 = fgets($myFile); $town = fgets($myFile); $postcode = fgets($myFile); $telephone = fgets($myFile); $email = fgets($myFile); fclose($myFile); ?> <h1>My Contact Details</h1> <p> The contact details on file are as shown below.<br> Edit the data and save your changes to file. </p> <form action="save_contact_details.php" method="post"> <table> <tr> <td align="right">Last name: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"lastname\" value=\"$lastname\">"?> </td> </tr> <tr> <td align="right">First name: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"firstname\" value=\"$firstname\">"?> </tr> <tr> <td align="right">Address 01: </td><td> <?php echo "<input size=\"30\" type=\"text\" name=\"address01\" value=\"$address01\">"?> </td> </tr> <tr> <td align="right">Address 02: </td><td> <?php echo "<input size=\"30\" type=\"text\" name=\"address02\" value=\"$address02\">"?> </td> </tr> <tr> <td align="right">Town / city: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"town\" value=\"$town\">"?> </td> </tr> <tr> <td align="right">Post code: </td><td> <?php echo "<input size=\"10\" type=\"text\" name=\"postcode\" value=\"$postcode\">"?> </td> </tr> <tr> <td align="right">Telephone: </td><td> <?php echo "<input size=\"15\" type=\"text\" name=\"telephone\" value=\"$telephone\">"?> </td> </tr> <tr> <td align="right">E-mail: </td><td> <?php echo "<input size=\"50\" type=\"text\" name=\"email\" value=\"$email\">"?> </td> </tr> <tr> <td> </td> <td colspan="2" align="left"><input type="submit" value="Save Changes"></td> </tr> </table> </form> </body> </html> create contact html code <html> <body> <h1>The contact details</h1> <p>Please enter your contact details:</p> <form action="save_contact_details.php" method="post"> <table> <tr> <td align="right">First name: </td> <td><input size="20" type="text" maxlength="15" name="firstname"></td> </tr> <tr> <td align="right">Last name: </td> <td><input size="20" type="text" maxlength="15" name="lastname"></td> </tr> <tr> <td align="right">Address line 1: </td> <td><input size="30" type="text" maxlength="50" name="address01"></td> </tr> <tr> <td align="right">Address line 2: </td> <td><input size="30" type="text" maxlength="50" name="address02"></td> </tr> <tr> <td align="right">Town / city: </td> <td><input size="20" type="text" maxlength="20" name="town"></td> </tr> <tr> <td align="right">Post code: </td> <td><input size="10" type="text" maxlength="10" name="postcode"></td> </tr> <tr> <td align="right">Telephone: </td> <td><input size="15" type="text" size="20" maxlength="15" name="telephone"></td> </tr> <tr> <td align="right">E-mail: </td> <td><input size="50" type="text" maxlength="50" name="email"></td> </tr> <tr> <td> </td> <td colspan="2" align="left"><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html>
Hi, I have a separate form created using Dreamweaver that calls a separate php script when the Submit button is clicked. Currently I am able display form validation messages in a new html page. If the user leaves fields blank, I would like the messages to appear on the form itself instead of in a new page. How do you make the messages from the php form validation code display into the calling html form? I know I could just do this with Dreamweaver but I would like to learn to do this using php. It might be easier to embed the code within the html page but I was thinking that using the separate script would be more secure. My form can be found here. Validation is working but opens a new page: http://www.tallfirshoa.com/adform.htm Thanks! Rob Hi.. been a while since I have touched php and need some help. What I am trying to do is have my links pull text from separate php files, and load them into main table. Here is my old php code..used to work.. I had my index.php with my website template on it. In the table I want my info to appear i put this code. <?php /* START MAIN AREA HERE */ if($news) include("news.php"); elseif($bio) include("bio.php"); elseif($draw) include("draw.php"); elseif($pic) include("pic.php"); else include("news.php"); /* END HERE */?> My link looks like this. <A HREF="?news=x" ONMOUSEOVER="changeImages('home', 'images/home-over.gif'); return true;" ONMOUSEOUT="changeImages('home', 'images/home.gif'); return true;"> <IMG NAME="home" SRC="images/home.gif" WIDTH=69 HEIGHT=31 BORDER=0 ALT=""></A> Any help much appreciated! Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } Hello there people. I'm looking for the easiest & most solid way to append 1 or 2 strings to a certain PDF file. I have an application which a logged-in user will be able to print. When he prints it, his name and a counter string must be appended in a blank space in the application. So I don't need to replace a string in a PDF or something, just append. The PDF file will always be the same: the application to be filled. I've heard somewhere that you can do it easily with the Zend framework. I've also heard for some other libraries like TCPDF & FPDF. Any suggestions? Thanks Here's what I need to do: I have a page that reads file and simply echos it. $mystring = file_get_contents($file); echo "$mystring"; There is one piece of info I need to parse out and then use as part of my page title. The phrase I need to parse is an HTML comment field and looks like this: <!--PageTitle=<some text here> --> I'm sure this is simple but I'm clueless as you can tell. How can I do this? DryAquaman Hi Community! :-) (Sorry for my average english) I recently started coding in php, till now, i allready have advanced skills in programming with C# and thus, had no problems writing my own script. Still, my script does not really work, i'm trying to check if a file contains a md5(string), but the script never finds the string. This is the script: (please don't mind any security issues, this is just a test. But if you have any tips and tricks to improve the security, i'd be glad to receive them) <?php $webname = $_POST["webname"]; $webcode = $_POST["webcode"]; $webpass = $_POST["webpass"]; if (file_exists("web/". $webname . ".html")) { $file = file_get_contents("web/". $webname . ".html", "r"); if (strpos(md5($webpass),$file) !== false) { $usergen = fopen("web/" . $webname . ".html", "w") or die("Unable to open file!"); fwrite($usergen, $webcode); fwrite($usergen, "<!--- ". md5($webpass) . "--->"); fclose($usergen); echo "Generated! You can view your site under /web/" . $webname . ".html"; } else { echo "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered."; } } else { $usergen = fopen("web/" . $webname . ".html", "w") or die("Unable to open file!"); fwrite($usergen, $webcode); fwrite($usergen, "<br><!--- ". md5($webpass) . " --->"); fclose($usergen); echo "Generated! You can view your site under /web/" . $webname . ".html"; } echo "<FORM><INPUT Type=\"button\" VALUE=\"Back\" onClick=\"history.go(-1);return true;\"></FORM>"; ?>What it does it pretty simple, you enter some html-code that'll be stored in the "webcode" variable, a password, let's say "apple" in "webpass" and the filename is stored in "webname". On first creation, a html-file is created with the <!--- md5(apple) ---> at it's end, the HTML Tags are needed to hide the string from any visitors. If someone wants to edit the File created before, he also enters "apple". Then the string will be looked up as md5(apple) in the file. If the strings match, it's true and the changes should be saved. Whatever i do, though, i'm allways ending up here if i try to edit an existing file: "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered."; As i said, i'm a newbie, i'd appreciate any tips and help. Thank you in advance! Is it pasible to find all occurrences of strings "North" and "North-East" in some txt file and save number of occurrences in some variables?? Hello, Okay for some reason i cannot do this, when i open a file in php and search for string, it doesn't seem to work, some codes i tried: Code: [Select] $filename = 'example.txt'; $searchfor = 'hello'; $fh = fopen($filename, 'r'); $olddata = fread($fh, filesize($filename)); if(strpos($olddata, $searchfor)) { //fount it } else { //can't find it } fclose($fh); (above it just sample text, i was hoping you could give me sample code that will work) I tried many others like strstr, stristr, preg_replace etc etc, doesn't seem to find it.. this is my text file: Code: [Select] sdfsdfsdfsdfsdf[b]hello[/b]sdvsdf dfadfsdfsdfsddfsdf sdfsdfsdfs sdffffffffffffffffffffdv vsvdsdsf I don't want to find it by line, i want to simply open the text file and find the string.. thanks.. Hi, I am relatively new to PHP, and I am making a php script that will FTP into a server and add a donator's ID to a text file. However, I need it to check and see if the user is already listed under a usergroup in that file, and if so, remove those lines of text. Here's an example of what values in the file look like. Basically, I don't know how I could compare the contents of the file and delete it or replace parts of it when necessary Code: [Select] "STEAM_0:0:33358541" { "deny" { } "group" "moderator" "name" "TR Cpt. K. Reese" "allow" { } } Also, notice the "deny"{} and "allow"{} These are used for storing special commands that you allow or disallow the user to have in a game. How would i get a PHP script to ignore that... This uses STEAM's framework for userids. All help is appreciated!! Thanks! This one stumped me, but maybe someone has figured it out. I'm trying to write a script that is able to decide whether a remote url is a directory or a file, this is fine until it comes to mod_rewrite(rewritten?) urls. ex. http://www.example.com/test Now this could be test.php,test.html etc., but in the rare case, it could also be a folder (example.com/test/index.php). Anyone have any ideas? I wanted to replace a strings in a large text file .. what would be the fastest way ?! e.g the text file contains .. INSERT INTO `subjects` VALUES (1, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (2, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (3, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (4, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (5, 'some text here', 'some text here', 'some text here'); I wanted to replace the string " VALUES (1, " with "VALUES (" in each line .. I'm new in PHP so any response would be much appreciated .. thanks Hello, We've been working on a page that allows users to create their own avatar to be displayed on their page. We can get the script working but the only way to show the image is to save it to a temp folder, we want to just save the string in the database and let the php show this wehen required here are the file http://test.digitaldemocracy.org.uk/test_avatar.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="author" content="John Munro, Democratise Ltd" /> <meta name="copyright" content="Democratise Ltd 2010" /> <meta name="description" content="Digital Democracy -" /> <meta name="keywords" content=" add here" /> <meta name="robots" content="index, follow" /> <meta name="revisit-after" content="1 week" /> <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5)" /> <link rel="SHORTCUT ICON" href="http://www.digitaldemocracy.co.uk/favicon.ico" /> <title>Digital Democracy -</title> <link href="css/site.css" rel="stylesheet" type="text/css" /> <link href="css/basic.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="avatars/avatar.css" type="text/css" /> <script type="text/javascript" src="avatars/avatar.js"></script> <style type="text/css"> /*<![CDATA[*/ <!-- body { background-image: url(images/background_paper.jpg); background-repeat: repeat; } --> /*]]>*/ </style> <script type="text/javascript"> //<![CDATA[ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-15681567-1']); _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); })(); //]]> </script> </head> <body> <div id="wrapper"> <div id="inner_wrapper"> <div class="header"> <div class="header_logo"> <img src="images/header_logo.png" width="190" height="55" alt="Digital Democracy" /> </div> <div class="header_link"> Make a<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> View<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> Vote on top<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> View<br/>results </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link_single_line"> Profile </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link_single_line"> More </div> <div id="header_search_bar"> <form action="Search" method="post"> <input name="Search" type="text" value="Search" size="15" /> <input name="Submit" type="button" value="Go" /> </form> </div> <div class="header_login"> <span class="header_login_text">Login / Register</span> </div> </div> <div id="info"> <div id="chosen_avatar"> <!--<p> avatar to be shown here when completed only - image shown below is thee to reference the saved code</p>--> <p><img src="<?php if (!empty($image)) { echo $filename; } else { echo 'http://test.digitaldemocracy.org.uk/avatar_creator.php?avatar[background]=bg_08&avatar[body]=body_01&avatar[head]=head_01&avatar[eyes]=blank&avatar[mouth]=blank&avatar[moustache]=blank&avatar[glasses]=blank&avatar[male_hair]=blank&avatar[female_hair]=blank';} ?>" title="Your chosen avatar (assembled as a PNG image)" alt="Your chosen avatar (PNG image)" /></p> <p>Your chosen avatar</p> </div> <form action="http://test.digitaldemocracy.org.uk/avatar_creator.php" method="get"> <div id="avatar_section"> <div id="avatar_stack"> <p> <img src="avatars/bg_01.png" alt="" /><input name="avatar[background]" type="radio" value="bg_01" checked="checked" /> <img src="avatars/bg_02.png" alt="" /><input name="avatar[background]" type="radio" value="bg_02" /> <img src="avatars/bg_03.png" alt="" /><input name="avatar[background]" type="radio" value="bg_03" /> <img src="avatars/bg_04.png" alt="" /><input name="avatar[background]" type="radio" value="bg_04" /> <img src="avatars/bg_05.png" alt="" /><input name="avatar[background]" type="radio" value="bg_05" /> <img src="avatars/bg_06.png" alt="" /><input name="avatar[background]" type="radio" value="bg_06" /> <img src="avatars/bg_07.png" alt="" /><input name="avatar[background]" type="radio" value="bg_07" /> <img src="avatars/bg_08.png" alt="" /><input name="avatar[background]" type="radio" value="bg_08" /> <img src="avatars/bg_09.png" alt="" /><input name="avatar[background]" type="radio" value="bg_09" /> </p> <p> <img src="avatars/body_01.png" alt="" /><input name="avatar[body]" type="radio" value="body_01" checked="checked" /> <img src="avatars/body_02.png" alt="" /><input name="avatar[body]" type="radio" value="body_02" /> <img src="avatars/body_03.png" alt="" /><input name="avatar[body]" type="radio" value="body_03" /> <img src="avatars/body_04.png" alt="" /><input name="avatar[body]" type="radio" value="body_04" /> <img src="avatars/body_05.png" alt="" /><input name="avatar[body]" type="radio" value="body_05" /> <img src="avatars/body_06.png" alt="" /><input name="avatar[body]" type="radio" value="body_06" /> <img src="avatars/body_07.png" alt="" /><input name="avatar[body]" type="radio" value="body_07" /> <img src="avatars/body_08.png" alt="" /><input name="avatar[body]" type="radio" value="body_08" /> </p> <p> <img src="avatars/head_01.png" alt="" /><input name="avatar[head]" type="radio" value="head_01" checked="checked" /> <img src="avatars/head_02.png" alt="" /><input name="avatar[head]" type="radio" value="head_02" /> <img src="avatars/head_03.png" alt="" /><input name="avatar[head]" type="radio" value="head_03" /> <img src="avatars/head_04.png" alt="" /><input name="avatar[head]" type="radio" value="head_04" /> <img src="avatars/head_05.png" alt="" /><input name="avatar[head]" type="radio" value="head_05" /> <img src="avatars/head_06.png" alt="" /><input name="avatar[head]" type="radio" value="head_06" /> <img src="avatars/head_07.png" alt="" /><input name="avatar[head]" type="radio" value="head_07" /> <img src="avatars/head_08.png" alt="" /><input name="avatar[head]" type="radio" value="head_08" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[eyes]" type="radio" value="blank" checked="checked" /> <img src="avatars/eyes_1.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_1" /> <img src="avatars/eyes_2.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_2" /> <img src="avatars/eyes_3.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_3" /> <img src="avatars/eyes_4.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_4" /> <img src="avatars/eyes_5.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_5" /> <img src="avatars/eyes_6.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_6" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[mouth]" type="radio" value="blank" checked="checked" /> <img src="avatars/mouth_1.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_1" /> <img src="avatars/mouth_2.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_2" /> <img src="avatars/mouth_3.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_3" /> <img src="avatars/mouth_4.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_4" /> <img src="avatars/mouth_5.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_5" /> <img src="avatars/mouth_6.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_6" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[moustache]" type="radio" value="blank" checked="checked" /> <img src="avatars/moustache_01.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_01" /> <img src="avatars/moustache_02.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_02" /> <img src="avatars/moustache_03.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_03" /> <img src="avatars/moustache_04.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_04" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[glasses]" type="radio" value="blank" checked="checked" /> <img src="avatars/glasses_01.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_01" /> <img src="avatars/glasses_02.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_02" /> <img src="avatars/glasses_03.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_03" /> <img src="avatars/glasses_04.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_04" /> <img src="avatars/glasses_05.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_05" /> <img src="avatars/glasses_06.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_06" /> <img src="avatars/glasses_07.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_07" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[hair 1]" type="radio" value="blank" checked="checked" /> <img src="avatars/m_hair_01.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_01" /> <img src="avatars/m_hair_02.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_02" /> <img src="avatars/m_hair_03.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_03" /> <img src="avatars/m_hair_04.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_04" /> <img src="avatars/m_hair_05.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_05" /> <img src="avatars/m_hair_06.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_06" /> <img src="avatars/m_hair_07.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_07" /> <img src="avatars/m_hair_08.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_08" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[hair 2]" type="radio" value="blank" checked="checked" /> <img src="avatars/f_hair_01.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_01" /> <img src="avatars/f_hair_02.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_02" /> <img src="avatars/f_hair_03.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_03" /> <img src="avatars/f_hair_04.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_04" /> <img src="avatars/f_hair_05.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_05" /> <img src="avatars/f_hair_06.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_06" /> <img src="avatars/f_hair_07.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_07" /> <img src="avatars/f_hair_08.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_08" /> </p> </div> </div> <p> </p> <p id="submit" > <input type="submit" value="Click here to save your personalised Avatar" /> </p> </form> <div id="hidden_spacer"> <p> </p> </div> </div> </div> </div> <div class="footer"> <div class="footer_content"> <div id="footer_democratise"> © Democratise Ltd </div> <div class="footer_link_single_line"> About us </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Contact </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Blog </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Help </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Privacy </div> </div> </div> </body> </html> And the file that runs the php and creates the images is <?php # form inputs in the correct stacking order from bottom to top $form_fields = array('background', 'body', 'head', 'eyes', 'mouth', 'moustache', 'glasses', 'hair 1', 'hair 2'); ob_start(); if(!isset($_GET['avatar'])) die; validate_inputs($form_fields); $filename = create_avatar($form_fields); //ob_end_clean(); //echo "hello"; //$image = output_image(ob_get_clean()); $image_output = ob_get_contents(); //ob_end_clean(); //echo $image; //$image = ob_get_contents(); //$image="data:image/png;base64, base64_encode($image)"; $image = 'test.digitaldemocracy.org.uk' . $_SERVER['REQUEST_URI']; //$image = $_SERVER['REQUEST_URI']; //echo $image; function validate_inputs($inputs) { foreach($inputs as $item) { if((preg_match('@(\.|/)@', $_GET['avatar'][$item])) or (!is_file('avatars/'.$_GET['avatar'][$item].'.png'))) { die(); } } } function create_avatar($inputs) { while($inputs) { $layer = @imagecreatefrompng('avatars/'. ($file = $_GET['avatar'][array_shift($inputs)]). '.png') or die('I could not open the avatars/'.$file); $layerWidth = imageSX($layer); $layerHeight = imageSY($layer); if(!isset($slate)) { $slate = @imagecreatetruecolor($layerWidth, $layerHeight); } @imagecopy($slate, $layer, 0, 0, 0, 0, $layerWidth, $layerHeight); @imagedestroy($layer); } imagetruecolortopalette ($slate, false, 256); //header('Content-Type: image/png'); $filename = 'temp'. rand(1,50) . '.png'; imagepng($slate, $filename); //imagepng($slate); imagedestroy($slate); return $filename; } function output_image($image) { $hash = md5($image); if(isset($_SERVER['HTTP_IF_NONE_MATCH'])){ if($hash == trim($_SERVER['HTTP_IF_NONE_MATCH'], '"')){ header("HTTP/1.x 304 Not Modified"); header('Etag: "'.$hash.'"'); die(); } } //header('Etag: "'.$hash.'"'); //header('Content-Type: image/png'); //imagepng($image); //echo $image; //return $image; } //header ("Location:test_avatar.php?image=$image"); include 'test_avatar.php'; ?> If anybody can help us it would be very appreciated Thanks John Munro Democratise.org Currently I am using a script that displays the entire directory. However I am trying to use preg_match to try and figure out
how to just link to one file from the directory via a search string from a form.
I am probably not even close so please bare with me
<?php if (isset($_POST['filelook'])) { $filez = $_POST['filelook']; } /* edit $path to the directory you want to use edit $file_types to change the file types to show */ function file_type($file) { $searchString = $filez; $path_chunks = explode("/", $file); $thefile = $path_chunks[count($path_chunks) - 1]; $dotpos = strrpos($thefile, "."); return strtolower(substr($thefile, $dotpos + 1)); } $file_count = 0; $path = "./WinFiles/files"; $file_types = array('png', 'jpg'); $p = opendir($path); while (false !== ($filelook = readdir($p))) { $files[] = $filelook; } sort($files); echo "<b> Your file results:</b><br> "; if (file_exists($filez) && is_readable($filez) && preg_match($filez)) { echo '<a href="download.php?f='.$filez.'">'.$filez.'</a> <br/>'; //find filename like name searched for... if($file_count == 0) { echo "<b>No file match your file types</b>"; } } ?> Hi to everyone. So, I have a little php code that reads line by line from a txt file, specifically i have 1 IP address for each line, and compares it with the current user's IP. It's like a little blacklist code. But it doesn't work. Can anyone see what i am doing wrong? Code: [Select] $file = fopen("ipblacklist.txt", "r") or exit("Unable to open file!"); //Output a line of the file until the end is reached $ipblacklist=''; $refile=''; while(!feof($file)) { if (fgets($file)== $_SERVER['REMOTE_ADDR']) $ipblacklist='error'; $refile=fgets($file); } fclose($file); Thank you in advance Hello Guys
I need help.
I found one PHP script for simple auto update of "system" (automatic updating of website for example)
http://maxmorgandesign.com/simple_php_auto_update_system/I want to adjust this script for my project, and In this code there is a line (on line 10): echo '<p>CURRENT VERSION: '.get_siteInfo('CMS-Version').'</p>';which variable should write in my page to define curent version of CMS? I try to googleit but unsuccessful :-/ Many thanks Hi all I wonder if someone can help me, basically I have a HTML form with a free text area, which looks like Code: [Select] <textarea name="details"></textarea> when I submit the form, I can print what was outputted using $details = $_POST['details']; print $details; The user is able to either enter plain text, like Code: [Select] this is my website profile or they can enter some text and a URL, like Code: [Select] this is my website [http://www.google.com,2] profile My question is, when I do my print statement using print $details; how can I get it to convert what has been posted, so that it outputs the following HTML Code: [Select] this is <a href="http://www.google.com">my website</a> profile so basically it would create a link using what was entered between Code: [Select] [] and then use Code: [Select] ,2 to determine how many words before the URL should be linked, so in my example, just the words Code: [Select] my website would be linked, as I defined Code: [Select] ,2 following the URL in the code. But then further to this, if I entered 0, using Code: [Select] ,0 how can I then get it to link all the text, like Code: [Select] <a href="http://www.google.com">this is my website profile</a> i'm very new to PHP, so some guidance would be a great help Thanks very very much, been racking my brain on how to do this and have tried so many things, all with massive failure Can someone help me out, I had a guy make some great changes to a script. works perfectly - however I want to modify it further and he's unavailable till tomorrow to discuss. Hopefully someone will be able to guide me: define('TBL_PROFILE_COUNTRY_FILTER', '`country_id` = \'IE\''); This line is based on users in a database from Ireland (IE) but what I need to do is make it so that this TBL_PROFILE_COUNTRY_FILTER doesnt just filter Ireland members but also those from Northern Ireland (Ni) as well. So my question is this - can I (and if so how) - can I add Ni to this define statement. Grateful for any guidance (php isn't my thing at all but I'm trying to pick up what I need when I need it). Thanks again. |