PHP - Help With Dynamic Image Changing
Please keep in mind, im a newbi at php as well as these forums, and I just started using it this week. I have some background in C programing and know a little VB.
I am currently trying to make a php based webpage that has 5 different images on it. I want each image to change with respect to what is written in a text file within the server space. So to better explain this, I have a text file that is named "status.txt". status.txt contents: active inactive active active active I want the first image to change to a different image if I change the first line of the text file to be inactive instead of active and the 2nd image to change if I change the 2nd line (inactive) to active and so forth on all the other images. I do know that i need to open the file, then read the file with fopen and fread and set what the contents that i read from the file equal to some variable (still not 100% sure im using the functions right). but im not sure how to set up the code so the image will change with respect to what is read from the text aka what the variable is equal too. I thought it would be a simple if statement but it seems more complicated then that. and futhermore, im not sure where to place the open file, should i do this in the header? so every time website refreshes, is opens the file and reads the txt file and changes with respect to that? Any help would be great! Thank you in advance. Similar TutorialsFolks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Any chance you could help me out with some probably simple code ? I need to change an image when the script change state. So instead of $Streamstatus "off"or "on" I would like to change an image. Cheers Code: [Select] <?php $request = 'http://api.own3d.tv/liveCheck.php?live_id='; $arg = 'Zerkilive'; $session = curl_init($request.$arg); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); if (preg_match("/true/",$response, $result)) { $streamStatus="on"; $color="green"; } else { $streamStatus="off"; $color="red"; } echo $streamStatus; ?> Hi! I am currently making a really simple photo blog. The query fetches every reference to the images which are stored on the server. I have a problem when it comes to dynamically cycling through these though. After running the query, I store each image reference in a twodimensional array like this: [["id"], ["date"], ["title"], ["filename"]] (an Array of Arrays). The image displays just fine by doing this: $pointer; //starting from the last element (image) in the array <img src="images/gallery/<?php echo $images[3][$pointer] ?>" alt="<?php echo $images[2][$pointer] ?>"> The problem is that, when I update the pointer, say for instance pointer++, the current image on the screen doesnt update. I know for a fact that the pointer updates, because I have echoed it. The basic idea is to have a previous and next link just under the image, so that the viewer can cycle the available images. Any help is greatly appreciated Hi
I'm trying to change an image when a certain link is clicked. The image is a logo of a company and the links that will be clicked is english, arabic, and Chinese.
So if someone clicks on Chinese then the logo changes to the Chinese version of the normal logo.
Here is my html
<?php $langArabic=''; $langChinese=''; $langSpanish=''; $langEng=''; $linkArabic=getSEOLink($page_id); $linkChinese=getSEOLink($page_id); $linkSpanish=getSEOLink($page_id); $linkEng=getSEOLink($page_id); $queryLink = mysql_query("SELECT * FROM $_SEO_TABLE WHERE `id_page`='".$page_id."'"); if(mysql_num_rows($queryLink) > 0){ $resultLink = mysql_fetch_object($queryLink); if($resultLink->url != ''){ $linkEng = $_HTTP_ADDRESS."".$resultLink->url; if($page_id == 1 || $page_id == '1'){ $linkEng = $_HTTP_ADDRESS; } } if($resultLink->url_arabic != ''){ $linkArabic = $_HTTP_ADDRESS."".$resultLink->url_arabic; } if($resultLink->url_chinese != ''){ $linkChinese = $_HTTP_ADDRESS."".$resultLink->url_chinese; } if($resultLink->url_spanish != ''){ $linkSpanish = $_HTTP_ADDRESS."".$resultLink->url_spanish; } } switch (urlExtension()) { case 'html': $langClass = ''; $langEng='langActive'; $langTag='en'; break; case 'ar': if($page->title_arabic == ''){ $langClass = '_arabic'; }else{ $langClass = '_arabic'; } $langArabic='langActive'; $langTag='ar'; break; case 'es': $langClass = ''; $langSpanish='langActive'; $langTag='es'; break; case 'cn': $langClass = ''; $langChinese='langActive'; $langTag='cn'; break; default: $langClass = ''; $langEng='langActive'; $langTag='en'; } ?> <a class="main-logo<?php echo $langClass;?>" href="javascript:void(0);"><img src="<?php echo $_HTTP_ADDRESS;?>images/logo-letters.png" /></a> <div class="language-selection-wrapper<?php echo $langClass;?> overlay-bg<?php echo $langClass;?> border-bottom-white<?php echo $langClass;?> padding-level-one<?php echo $langClass;?>"> <div class="language-inner-wrapper<?php echo $langClass;?>"> <a class="<?php echo $langEng;?>" href="<?php echo $linkEng;?>">English</a><span>|</span> <a class="<?php echo $langArabic;?>" href="<?php echo $linkArabic;?>">العربيّة</a><span>|</span> <a class="<?php echo $langSpanish;?>" href="<?php echo $linkSpanish;?>">Español</a><span>|</span> <a class="<?php echo $langChinese;?>" href="<?php echo $linkChinese;?>">中文</a> <div class="clearboth"></div> </div> Hi, i am creating a web application, and i would like some help/advise on how to tackle a problem. I need to make an image i have into a contact form, with four fields, which basically posts information into a database. I am not sure how i would go about doing this as i will need to make each of the fields dynamic to post the data. I have attached the image to make my point a bit clearer. thanks What I am working on is a background to a user input comment -- essentially a framed box around the comment. For some reason I cannot fathom but which is probably simple, I can't get the image height variable, (set by the length of the comment) to be seen by the code outputting the framed box. So here's what I got: To set the image position and height variables I put this code inside of a while loop, since there are multiple comments in the DB: Code: [Select] //Looks at the comment in the DB //Calculates the number of lines based on 75 characters per line $line_count = ceil(strlen($row3['comment'] /75)); //This sets the position of the username who posted the comment $username_pos = ($text_pos + ($line_count * 33)) . ".00pt"; //Sets the initial starting position of the framed box on the page $box_pos = $text_pos - 42.00 . ".00pt"; //Sets the height of the framed box $box_ht = $username_pos + 50 . ".00pt"; //Outputs the framed box echo "<img src='images/blue table.gif' style='position:absolute; left:140.00pt; top:$box_pos'; height:$box_ht'; width = 570.00pt; z-index:-1 class='cc01'>"; There is also code outputting the comment and username which seems to work just fine. The result is a pretty box framing the comment, but the outputted image always ends up with the same height, which obviously doesn't work because each comment in the DB can have a different number of lines and would need a different size box. Just to be clear, the source image is much larger than what can be produced by this code. If anyone has any suggestions, I'd really appreciate it. Thanks! Hi there, I have a simple question - is it possible to send out an html email containing PHP/MySQL code so that when the user receives the email it checks the date and serves up content from a database? I have created a page that works fine online, but when I try to email the page, it doesn't work from within the user's email client (such as outlook, or gmail). When I look at the raw email source, it looks like the PHP code isn't getting executed by the email program. If anyone knows a reason or workaround, I would appreciate it! Thanks in advance, Rick Code: [Select] <?php $day = date("Y-m-d"); // Connects to your Database mysql_connect("empowermentoftheday.com", "username", "password") or die(mysql_error()) ; mysql_select_db("etd_emails") or die(mysql_error()) ; if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $query = sprintf("SELECT * FROM daily WHERE date = '%s'", mysql_real_escape_string($day)); // Perform Query $Recordset1 = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$Recordset1) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="Free inspirational Picture of the Day as well as a Free daily Wellness Break. Start your day off right and Empower Yourself Today. Empowerment of the Day is meant to inpire you each and every day and is brought to you by the Remakable Success Group Team.Empower Yourself Today." /> <meta name="keywords" content="inspirational quote, picture of the day, wellness quote, inspirational saying, inspirational story, today's wellness break, empowerment, empower yourself, empowerment of the day, health tip, wellness tip" /> <title>Empowerment Of The Day</title> </head> <body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="100%" align="center"> <div style="background:#DBAE13"> <img src="http://www.empowermentoftheday.com/email/images/header.jpg" alt="Empowerment of the Day" width="650" height="77" /></div> <div> <table width="650" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="middle"><img src="http://www.empowermentoftheday.com/email/images/message2.jpg" alt="Picture of the Day" width="306" height="34" vspace="15" /></td> </tr> <tr> <td align="center" valign="middle"> <table border="0" cellspacing="0" cellpadding="5" bgcolor="#000000"> <tr height="10px"> <td height="10px"></td> <td height="10px"></td> <td height="10px"></td> </tr> <tr> <td> </td> <td><img src="http://www.empowermentoftheday.com/email/images/photos/<?php echo $row_Recordset1['photo']; ?>" alt="Picture of the Day" /></td> <td> </td> </tr> <tr> <td> </td> <td align="center"> <div><font color="#FFFFFF" face="Helvetica, Arial, sans-serif"><?php echo $row_Recordset1['quote']; ?></font></div> </td> <td> </td> </tr> </table> </td> </tr> <tr> <td align="center" valign="middle"> <img src="http://www.empowermentoftheday.com/email/images/message3.jpg" alt="Today's Wellness Break" width="360" height="44" vspace="15" /></td> </tr> <tr> <td align="center" valign="middle"><p><font color="#000000" face="Helvetica, Arial, sans-serif"><?php echo $row_Recordset1['wellness']; ?><br> <br> </font></p></td> </tr> </table> <script language="JavaScript1.2" type="application/javascript"> /* Disable right click script II (on images)- By Dynamicdrive.com For full source, Terms of service, and 100s DTHML scripts Visit http://www.dynamicdrive.com */ var clickmessage="Right click disabled on images!" function disableclick(e) { if (document.all) { if (event.button==2||event.button==3) { if (event.srcElement.tagName=="IMG"){ alert(clickmessage); return false; } } } else if (document.layers) { if (e.which == 3) { alert(clickmessage); return false; } } else if (document.getElementById){ if (e.which==3&&e.target.tagName=="IMG"){ alert(clickmessage) return false } } } function associateimages(){ for(i=0;i<document.images.length;i++) document.images[i].onmousedown=disableclick; } if (document.all) document.onmousedown=disableclick else if (document.getElementById) document.onmouseup=disableclick else if (document.layers) associateimages() </script> </div> <div style="background:#D0A615"> <img src="http://www.empowermentoftheday.com/email/images/footer.jpg" alt="Copyright 2010 Remarkable Success Group Inc. Design by Ortega.ca" width="650" height="74" border="0" usemap="#Map" /> <map name="Map"><area shape="rect" coords="456,28,617,55" href="http://www.ortega.ca" alt="Design by Ortega.ca" target="_blank"></map> </map></div> <!-- GOOGLE ANALYTICS --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-2910054-6']); _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> </td> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Hi, I currently have this code which displays text on clicking the image: <a href="javascript:;" onclick="document.getElementById('text').style.display='block';window.open('url...');"><img src="image..."></a> <div id="text" style="display:none;"> ...text to be displayed here </div> it works fine but I want to integrate this with php which is where I am struggling. I have a mySQL database with 4 fields (id;name;description;url), what i would like to do is name the div to be opened on click with the 'id' field from the database so that it would become '<div id="id"> and then more than one function could be implemented on each page. I would also like to replace '...text to be displayed here' with the field 'name' from the database and '...url' with the field 'url from the database. Any help would be very much appreciated. Thanks in advance. Ok so I have a form to submits to a .php file that creates an image. This works fine, but I also want the info from the form to be sent to MySQL database. The problem is that something in a script I "required" called core.inc.php is interfering and so no image is output. Here is core.inc.php: Code: [Select] <?php ob_start(); session_start(); $current_file = $_SERVER['SCRIPT_NAME']; if(isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) { $http_referer = $_SERVER['HTTP_REFERER']; } function loggedin() { if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) { return true; } else { return false; } } function getuserfield($field) { $query="SELECT `$field` FROM `Users` WHERE `id`='".$_SESSION['user_id']."'"; if($query_run=mysql_query($query)) { if($query_result = mysql_result($query_run, 0, $field)) { return $query_result; } } } ?> Here is the code for the image creating .php file: Code: [Select] <?php require 'connect.inc.php'; require 'core.inc.php'; $title = $_REQUEST['title'] ; $user_id = getuserfield('id'); $query = "INSERT INTO `---` VALUES ('".mysql_real_escape_string($title)."','".mysql_real_escape_string($user_id)."')"; $query_run = mysql_query($query); //There is some more code in here obviously, but it's irrelevant header('Content-type: image/png'); imagepng($image_f); imagedestroy($image_f) Can anybody give me some idea of what is conflicting or what I can do to fix it? I wonder whether someone may be able to help me please. I've put together the following script which saves user defined images to server folders using the Aurigma Image Uploader software. Code: [Select] <?php require_once 'Includes/gallery_helper.php'; require_once 'ImageUploaderPHP/UploadHandler.class.php'; $galleryPath = 'UploadedFiles/'; function onFileUploaded($uploadedFile) { global $galleryPath; $packageFields = $uploadedFile->getPackage()->getPackageFields(); $username=$packageFields["username"]; $locationid=$packageFields["locationid"]; $usernamefolder = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['username']); $locationfolder = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['locationid']); $dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['folder']); $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $usernamefolder . DIRECTORY_SEPARATOR . $locationfolder . DIRECTORY_SEPARATOR; $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR; if (!is_dir($absGalleryPath)) mkdir($absGalleryPath, 0777, true); chmod($absGalleryPath, 0777); if (!is_dir($absGalleryPath . $dirName)) mkdir($absGalleryPath . $dirName, 0777, true); chmod($absGalleryPath . $dirName, 0777); if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) initGallery($absGalleryPath, $absThumbnailsPath, FALSE); $originalFileName = $uploadedFile->getSourceName(); $files = $uploadedFile->getConvertedFiles(); $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName); $sourceFile = $files[0]; if ($sourceFile) $sourceFile->moveTo($absGalleryPath . $sourceFileName); $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName); $thumbnailFile = $files[1]; if ($thumbnailFile) $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName); $descriptions = new DOMDocument('1.0', 'utf-8'); $descriptions->load($absGalleryPath . 'files.xml'); $xmlFile = $descriptions->createElement('file'); // <-- please check the following line $xmlFile->setAttribute('name', $_POST['folder'] . '/' . $originalFileName); $xmlFile->setAttribute('source', $sourceFileName); $xmlFile->setAttribute('size', $uploadedFile->getSourceSize()); $xmlFile->setAttribute('originalname', $originalFileName); $xmlFile->setAttribute('thumbnail', $thumbnailFileName); $xmlFile->setAttribute('description', $uploadedFile->getDescription()); $xmlFile->setAttribute('username', $username); $xmlFile->setAttribute('locationid', $locationid); $xmlFile->setAttribute('folder', $dirName); $descriptions->documentElement->appendChild($xmlFile); $descriptions->save($absGalleryPath . 'files.xml'); } $uh = new UploadHandler(); $uh->setFileUploadedCallback('onFileUploaded'); $uh->processRequest(); ?> This code saves the files in the following structu UploadedFiles (Pre-existing folder) 'username' (Subfolder created dynamically on image upload if it doesn't already exist. This folder contains the 'location' folder) 'location' (Subfolder created dynamically on image upload if it doesn't already exist. This contains original image, 'files.xml' and 'Thumbnails' folder) 'Thumbnails' (Subfolder created dynamically on image upload if it doesn't already exist. This contains thumbnail of original image) I'm now trying to put together a script which creates an image gallery, with those images pertinent to the current user and location. The code below is the piece of my script which deals with the loading of the images. Code: [Select] <?php $galleryPath = 'UploadedFiles/'; $thumbnailsPath = $galleryPath . 'Thumbnails/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions->load($absGalleryPath . 'files.xml'); ?> The initial problem I had, was resolved from guidance I received on this site, and that was to find the correct 'realpath' of the 'Thumbnails' folder and 'files.xml' These are as follows: Quote /homepages/2/d333603417/htdocs/development/UploadedFiles/IRHM73/1 and Quote /homepages/2/d333603417/htdocs/development/UploadedFiles/IRHM73/1/Thumbnails with 'IRHM73' being the 'username' value and '1' the 'location' value. The problem I now have lies within this line of code: `$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;` Because the 'username' and 'location' are dynamic and hence contain different values for each user and location, I've found it impossible to find a way of creating the correct file path to open the 'Thumbnails' folder and 'files.xml'. I had tried this: Code: [Select] <?php $galleryPath = 'UploadedFiles/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $usernamefolder . DIRECTORY_SEPARATOR . $locationfolder . DIRECTORY_SEPARATOR; $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions->load($absGalleryPath . 'files.xml'); ?> But I receive the following error: DOMDocument::load() domdocument.load: I/O warning : failed to load external entity /homepages/2/d333603417/htdocs/development/UploadedFiles/'files.xml'; in /homepages/2/d333603417/htdocs/development/gallery.php on line 13 and line 13 is this: Code: [Select] $descriptions->load($absGalleryPath . 'files.xml'); I really am stumped with what to do next to get this to work. I appreciate that this is a fairly lengthy post, but thought it would be better to post all the information. I just wondered whether someone could perhaps take a look at this and let me know where I'm going wrong and how I can get it to work. Many thanks and regards Hi guys, Here is what I have so far: http://www.autoshopgarage.com/new-era/generate.php What I am trying to do is instead of having Line 1 and Line 2, I want to just have one big textarea so I don't have to limit the user so much. I did it this way because I want to have two versions of text, the light version and the bold version. Is it possible to have two different fonts with just one textarea of text? Right now I have two functions: Quote ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); So I would limit that to just 1, and it would automatically wordwrap but what would I put for the $font variable? Is this even possible? I was thinking of just using BBCode so they could type in [b*]Bold Text[/b*] and it would use the Bold version of the font if it sees that. Any help is appreciated. Thanks! Here is the full code: Quote <?php $first = $_GET['first']; $last = $_GET['last']; $font_color = $_GET['color']; header("Content-type: image/png"); $image = imagecreatefrompng ( "banner_blank.png" ); $color_black = imagecolorallocate($image, 0, 0, 0); $color_red = imagecolorallocate($image, 255, 0, 0); if($font_color == "Red") { $color = $color_red; } elseif($font_color == "Black") { $color = $color_black; } $font1 = 'HelveticaNeueLTStd-BdEx.ttf'; $font2 = 'HelveticaNeueLTStd-LtEx.ttf'; $fontSize = "21"; ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); imagepng ( $image ); imagedestroy ( $image ); ?> 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. Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete As I am VERY new to PDO, can someone help me in converting the below 2 codes so that I can setup the testing site knowing at least this part works. Below is the old SQL that I need to convert but don't have to foggiest on where to start. If I can get some help with this I can slowly work through the rest of my site with a bit more ease. LOGIN CODE: <?php if($_POST['submit']){ $Username = protect($_POST['Username']); $Password = protect(sha1($_POST['Password'])); if(!$Username || !$Password){ echo "<center>Please enter your <b>Username</b> and <b>Password</b>!</center>"; }else{ $res = mysql_query("SELECT * FROM `eusers` WHERE `Username` = '".$Username."'"); $num = mysql_num_rows($res); if($num == 0){ echo "<center>The <b>Username</b> or <b>Password</b> you supplied is incorrect!</center>"; }else{ $res = mysql_query("SELECT * FROM `eusers` WHERE `Username` = '".$Username."' AND Password = '".$Password."'"); $num = mysql_num_rows($res); if($num == 0){ echo "<center>The <b>Password</b> you supplied is incorrect!</center>"; }else{ $row = mysql_fetch_assoc($res); if($row['Active'] != 1){ echo "<center>Your login has been <b>deactivated</b>, Please contact your Manager for assistance.</center>"; }else{ header('Location: secure.php'); $time = date('U')+7200; //2 Hours mysql_query("UPDATE `eusers` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); $_SESSION['uid'] = $row['id']; }}}}} ?> ACCESS GRANTED (Each Page): <?php if(strcmp($_SESSION['uid'],"") == 0){ printf("<script>location.href='index.php'</script>"); }else{ $time = date('U')+7200; //2 Hours $update = mysql_query("UPDATE `eusers` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); } ?>
Hi, I am changing my ISP and need to import my databases.
Do I I have to create a new datarbase or can I change my database name to import?
My new host has a different database prefix ie: -web147xxxxxxxx
My old one was arewene1_wor1.
Many thanks.
Hi I'm using a form that uses number_format. It works fine until the number in question gets into the thousands. I can enter "3000", click Calculate and it comes back as "3,000.00" which is perfect. But if I click Calculate again, it changes to "3.00". How can I get it to remain "3,000.00"? Here's the code: Code: [Select] <form action="test.php" method="POST" > <?php if (empty($_POST['data1'])) { $number = ''; } else { str_replace(",","",$_POST['data1']); $number = number_format((double)$_POST['data1'],2); } ?> <input type="text" style="40" name="data1" value="<?php echo $number; ?>"> <input type="submit" name="submitCalc" value="Calculate" /><br /> <a href="test.php">Reset Form</a> </form> Hi guys, i have a system and was asked to develop the site with the current system. These are sometimes a pain but it is an old system and i'm trying to change the url's which is seems to be hard to do with this kind of code. set_time_limit(60); include 'includes/config.php'; include 'includes/logfile.php'; include 'includes/databasefile.php'; include 'includes/templatefile.php'; $log = new cLog; $db = new cDatabase; //first run ssl check if necessary if ($_SERVER['SERVER_PORT'] == "80" && $sslredirect == 1) { header ("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?" . $_SERVER['QUERY_STRING']); exit(0); } //first, determine page requested list ($junk, $request) = split ("\?/", $_SERVER['REQUEST_URI']); list ($uri, $data) = split ("!", $request); $uriarray = split ("/", $uri); //check for login/logout request list ($junk, $request) = split ("\?", $_SERVER['REQUEST_URI']); if ($request == 'login') { header ("Location: login.php"); exit(0); } else if ($request == 'logout') { header ("Location: logout.php"); exit(0); } if ($data != "") { //parse internal variables $dataarray = split ("&", $data); foreach ($dataarray as $line) { list ($cmd, $val) = split ("=", $line); $arr_cmds[$cmd] = urldecode ($val); } } $pagename = $db->escape($uriarray[count($uriarray)-2]); $sectionname = $db->escape($uriarray[count($uriarray)-3]); if ($pagename == "") { $pagename = "home"; } if ($sectionname == "") { $sectionname = "home"; } $urlpagename = $pagename; $urlsectionname1 = $sectionname; $urlsectionname2 = $db->escape($uriarray[count($uriarray)-4]); //handle any commands, then redirect back to page $cmd = $_REQUEST['cmd']; if ($cmd == "-displayelement") { $elementid = $db->escape($_REQUEST['elementid']); if ($_REQUEST['surpresshtml'] == "") { echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'></head>\n"; } if ($_REQUEST['global'] == "1") { $query = $db->query("select ComponentName, Data from table_globalelements where (ElementID = '$elementid')"); } else { $query = $db->query("select ComponentName, Data from table_elements where (ElementID = '$elementid')"); } $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); //find matching component and launch display function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) { include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'display'), $data); break; } } if ($_REQUEST['surpresshtml'] == "") { echo "</body></html>\n"; } exit (0); } else if ($cmd == '-editelement') { $elementid = $db->escape($_REQUEST['elementid']); if (isset($_SESSION['UserID'])) { $query = $db->query("select UserID, AdminFlag from table_users where (UserID = '" . $_SESSION['UserID'] . "')"); $r = $db->fetch_array($query); $userid = $r['UserID']; $adminflag = $r['AdminFlag']; if ($adminflag != "1") { $query = $db->query ("select ComponentName, Data, PageID from table_elements where (ElementID = '$elementid' and UserID = '$userid')"); } else { $query = $db->query ("select ComponentName, Data, PageID from table_elements where (ElementID = '$elementid')"); } $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); $pageid = $r['PageID']; //handle request $cmd = $_REQUEST['greyboxcmd']; if ($cmd == 'save') { $elementid = $db->escape($_REQUEST['ElementID']); $data = $db->escape($_REQUEST['Data']); //find matching component and launch save function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; $data = call_user_func(array($currentcomponentname, 'save')); if ($adminflag != "1") { $query = $db->query("update table_elements set Data = '$data' where (ElementID = '$elementid' and UserID = '$userid')"); } else { $query = $db->query("update table_elements set Data = '$data' where (ElementID = '$elementid')"); } echo "<script type='text/javascript'>parent.location.reload(true); parent.GB_hide();</script>\n"; exit(0); } } echo "Error: component not found..."; } //find matching component and launch edit function echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'><script type='text/javascript' src='templates/openwysiwyg/wysiwyg.js'></script></head>\n"; echo "<body style='text-align: center;'><form name='Form0' enctype='multipart/form-data' method='post' action='" . $_SERVER['REQUEST_URI'] . "'>\n"; $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'edit'), $data); break; } } echo "<input type='hidden' name='ElementID' value='$elementid'><input type='submit' name='Save' value='Save' class='smallbutton'>\n"; echo "<input type='button' name='Cancel' value='Cancel' onclick='parent.GB_hide();' class='smallbutton'>\n"; echo "<input type='hidden' name='greyboxcmd' value='save'></form></body></html>\n"; exit (0); } else { echo "<script type='text/javascript'>parent.GB_hide();</script>\n"; exit (0); } } else if ($cmd == '-editglobalelement') { $elementid = $db->escape($_REQUEST['elementid']); if (isset($_SESSION['UserID'])) { $query = $db->query("select UserID, AdminFlag from table_users where (UserID = '" . $_SESSION['UserID'] . "')"); $r = $db->fetch_array($query); $userid = $r['UserID']; $adminflag = $r['AdminFlag']; if ($adminflag != "1") { echo "Security - Out of bounds"; exit(0); } $query = $db->query ("select ComponentName, Data from table_globalelements where (ElementID = '$elementid')"); $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); //handle request $cmd = $_REQUEST['greyboxcmd']; if ($cmd == 'save') { $elementid = $db->escape($_REQUEST['ElementID']); $data = $db->escape($_REQUEST['Data']); //find matching component and launch save function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; $data = call_user_func(array($currentcomponentname, 'save')); $query = $db->query("update table_globalelements set Data = '$data' where (ElementID = '$elementid')"); echo "<script type='text/javascript'>parent.location.reload(true); parent.GB_hide();</script>\n"; exit(0); } } echo "Error: component not found..."; } //find matching component and launch edit function echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'><script type='text/javascript' src='templates/openwysiwyg/wysiwyg.js'></script></head>\n"; echo "<body style='text-align: center;'><form name='Form0' enctype='multipart/form-data' method='post' action='" . $_SERVER['REQUEST_URI'] . "'>\n"; $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'edit'), $data); break; } } echo "<input type='hidden' name='ElementID' value='$elementid'><input type='submit' name='Save' value='Save' class='smallbutton'>\n"; echo "<input type='button' name='Cancel' value='Cancel' onclick='parent.GB_hide();' class='smallbutton'>\n"; echo "<input type='hidden' name='greyboxcmd' value='save'></form></body></html>\n"; exit (0); } else { echo "<script type='text/javascript'>parent.GB_hide();</script>\n"; exit (0); } } //lookup page details $query = $db->query("select p.PageID, p.PageTitle, p.SectionID, p.TemplateID, p.UserID, p.LastUpdate, p.SectionName, s.SectionTitle, s.GroupID, s.Protected, p.Keywords, p.PageName from table_pages as p left join table_sections as s on s.SectionName = p.SectionName where (p.PageName = '$pagename' and s.SectionName = '$sectionname') limit 1"); if (!$pagedetails = $db->fetch_array($query)) { echo "404"; exit(0); } //check for privileges section if ($pagedetails[8] != "" && $pagedetails[8] != "0") { $sectionname = stripslashes($pagedetails[6]); if (!isset($_SESSION['Username']) && !isset($_REQUEST['Username'])) { echo "This is a restricted area. Please login.<br/><br/>"; echo "<form action='index.php' method='get'>Username: <input type='text' name='Username'><br/>\n"; echo "Password: <input type='password' name='Password'><br/>\n"; echo "<input type='submit' name='Login' value='Login'></form><br/>\n"; exit; } else { $username = $db->escape ($_REQUEST['Username']); $password = $db->escape ($_REQUEST['Password']); if ($username == "") { $username = $db->escape ($_SESSION['Username']); } if ($password == "") { $password = $db->escape ($_SESSION['Password']); } $query = $db->query("select UserID, Password, RealName, Email, GroupID, AdminFlag from table_users where (Username = '$username')"); $r = $db->fetch_array($query); $dbpassword = $r['Password']; if ($password == $dbpassword) { $_SESSION['Username'] = $username; $_SESSION['UserID'] = $r['UserID']; $_SESSION['RealName'] = $r['RealName']; $_SESSION['Email'] = $r['Email']; $_SESSION['GroupID'] = $r['GroupID']; } } if ($_SESSION['GroupID'] != $pagedetails[8]) { echo "This is a restricted area. Please login.<br/><br/>"; echo "<form action='index.php' method='get'>Username: <input type='text' name='Username'><br/>\n"; echo "Password: <input type='password' name='Password'><br/>\n"; echo "<input type='submit' name='Login' value='Login'></form><br/>\n"; exit; } } else { //check login details if user appears to be already logged in if (isset($_SESSION['Username'])) { $username = $db->escape ($_SESSION['Username']); $password = $db->escape ($_SESSION['Password']); $query = $db->query("select UserID, Password, RealName, Email, GroupID, AdminFlag from table_users where (Username = '$username')"); $r = $db->fetch_array($query); $dbpassword = $r['Password']; if ($password == $dbpassword) { $_SESSION['Username'] = $username; $_SESSION['UserID'] = $r['UserID']; $_SESSION['RealName'] = $r['RealName']; $_SESSION['Email'] = $r['Email']; $_SESSION['GroupID'] = $r['GroupID']; } } } //load template $tplate = new cTemplate($pagedetails['TemplateID'], $pagedetails['PageID']); $tplate->loadtemplate(); //add logout button if (isset($_SESSION['UserID'])) { echo "<div align='center'><small><a href='index.php?logout'>logout</a></small></div>\n"; } //log request if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv(HTTP_X_FORWARDED_FOR); } else { $ip = getenv(REMOTE_ADDR); } $log->writelog("/$sectionname/$pagename", "Access"); In the includes/templatefile.php file the code is like: function parsetemplate($templatefile) { global $db, $pageid, $pagedetails, $fullbaseurl, $adminemail; //first, find internal metacodes $pagetitle = stripslashes($pagedetails[1]); $lastupdate = date('l dS \of F Y h:i:s A', $pagedetails[5]); $sectiontitle = stripslashes($pagedetails[7]); $sectionname = stripslashes($pagedetails[6]); $templatefile = str_replace ("!PAGETITLE!", $pagetitle, $templatefile); $templatefile = str_replace ("!ADMINEMAIL!", $adminemail, $templatefile); $templatefile = str_replace ("!REQUEST_DOCUMENTID!", $_REQUEST['DocumentID'], $templatefile); $templatefile = str_replace ("!SECTIONTITLE!", $sectiontitle, $templatefile); $templatefile = str_replace ("!LASTUPDATE!", $lastupdate, $templatefile); $templatefile = str_replace ("!URL!", $_SERVER['REQUEST_URI'], $templatefile); $templatefile = str_replace ("!FULLBASEURL!", $fullbaseurl, $templatefile); $templatefile = str_replace ("!KEYWORDS!", $pagedetails[10], $templatefile); if ($_SESSION['UserID'] != "") { $templatefile = str_replace ("!LOGINDETAILS!", "- You are logged in as " . $_SESSION['Username'], $templatefile); } else { $templatefile = str_replace ("!LOGINDETAILS!", "", $templatefile); } $templatefile = str_replace ("!SECTIONLINK!", $fullbaseurl . "?/" . $sectionname . "/Home/", $templatefile); What i am getting via the links a Code: [Select] http://www.mydomain.com/?/Shop/Home/ How do i get rid of the "?" mark and the "/Home/". The /Home/ is also stored in the Database. I have tried a number of solutions by getting rid of the "?" and "/Home/" but i get the 404 error as the code shows. Can you please help with this? Salting passwords... How can you update the salting without getting all the users to change their password? Is the salting set in stone once created? Hi all I have a string called $voucher_code which is a value used to deduct or add value to a shopping cart. If the value is a minus I need it to show the minus sign, or if it's a plus value, it needs to show a plus sign. Here's my code: <strong>£ -".number_format(($voucher_code),2)."</strong> How do I modify the above code to show + instead of -- which it does at the moment? Many thanks for your help Pete Hi, I have a second website under the same domain www.lucyeleanorbrown.com/weddings.html which I wanted to change to www.weddings.lucyeleanorbrown.com, I have been looking around for PHP for this but am unsure of what to search for, could anyone give me a suggestion? Thank you |