PHP - Automatically Get Filename As Unique Id For Disqus Comment Boxes.
I want to add comments to my website, which is built in php. I am planning on using http://www.disqus.com/ coz i want to be able to backup my comments . I used http://www.htmlcommentbox.com/ before and put the code in a php file and inserted this php code <?php include("includes/comment.php"); ?> , to where i want comments to be displayed in my web pages. But for Disqus I must use a unique id number or url with the Disqus code for each page on my website. I want to use the same code for all pages. Can i use this code Code: [Select] <?php $currentFile = $_SERVER["PHP_SELF"]; $parts = Explode('/', $currentFile); echo $parts[count($parts) - 1]; ?>OR THIS (results seem the same, in the my example at the bottom of this, i used the code below) Code: [Select] <?php echo basename ( $_SERVER['PHP_SELF'] ) ; ?> Here is the Disqus code in which i want to insert the above php. Code: [Select] <div id="disqus_thread"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'example'; // required: replace example with your forum shortname // The following are highly recommended additional parameters. Remove the slashes in front to use. // var disqus_identifier = 'unique_dynamic_id_1234'; // var disqus_url = 'http://example.com/permalink-to-page.html'; /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a> And this is the Disqus code after i inserted the php. Code: [Select] <div id="disqus_thread"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'example'; // required: replace example with your forum shortname // The following are highly recommended additional parameters. Remove the slashes in front to use. // var disqus_identifier = 'unique_dynamic_id_1234'; // var disqus_url = '<?php echo basename ( $_SERVER['PHP_SELF'] ) ;?>'; /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a> Do you think this will work or is there a better method. I have used the php code on a test php page and the result was index.php . How can i just get index as the result. How this is explained ok. Thanks for taking the time to read this Similar TutorialsI am new to PHP and learning as I go I am stuck with a piece of code that I am trying to change. I have a php application that has tickboxes in and some are checked as standard. I want to change the tick box setting to be unchecked as standard. Here is the code. <label><input type="checkbox" name="notify" value="1" <?php echo (!isset($_SESSION['as_notify']) || !empty($_SESSION['as_notify'])) ? 'checked="checked"' : ''; ?> /> <?php echo $hesklang['seno']; ?></label><br /> I have tried everything I know but since I do not know that much I have been unable to change the standard. I am sure it is something small that I am overlooking. Anyone out there know what I am doing wrong? I just signed up on Disqus.
Link: https://disqus.com/
My Question:
Can this commenting system only be used for those platfroms which one can choose?
I was looking to use this for my own web application (in PHP).
If this may not work with Disqus, is there something similar to Disqus out there, quick and easy to set up?
CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=358814.0 I have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322815.0 Code: [Select] <form name="commentbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <textarea name="comment" cols="20" rows="2" onclick="document.commentbox.comment.value='';" onfocus="this.style.borderColor='yellow';" onblur="this.style.borderColor='blue';" />Comment...</textarea> </td></tr> $commentcheck = $_POST['comment']; if ($commentcheck == "Comment...") { die(' <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\"> '); }else why does this not refresh if i comment "Comment..." it just dies and doesnt echo anything I want to validate my PHP files to ensure that I didn't forget to import all the classes assigned to attributes. I will be using ReflectionClass to do so and need the FQCN's and not the filenames. Originally, I tried get_declared_classes(), however, ran into issues where a class was already declared. I came up with the following which appears to work, however, it was created based on trial and error and suspect there might be edge cases where it will not provide the desired results (and it is pretty damn ugly as well). How would you recommend doing so? A couple thoughts a Use composer to come up with the classes based on filename and use either vendor/Composer autoload_classmap.php or autoload_static.php. I don't really like this approach as it requires me to update composer to add any new files. Use composer but figure out how it generates the class map and use a similar approach. Appears that it is using phpstan or some other utility but I haven't really investigated. Use some third party script to generate the class maps. If so, please provide recommendations. Use some more modern approach other than PhpToken. If so, please provide recommendations. Use get_declared_classes() to get a base line and then require the PHP file to find the added class names and somehow deal with issues related to classes already being declared. Use tokens and my parseFile() method. If so, any recommendations on changing?PS. I originally wasn't 100% that attributes in traits and abstract classes would be propagated to the concrete class, but I should have known it to be true and this was confirmed by testing. At this time, I really just need the concrete classes, however, maybe in the future I will use the script to do some analysis on interfaces, traits, etc.
private function parseFile(string $filename):array { $getNext=null; $getNextNamespace=false; $skipNext=false; $isAbstract = false; $rs = ['namespace'=>null, 'class'=>[], 'trait'=>[], 'interface'=>[], 'abstract'=>[]]; foreach (\PhpToken::tokenize(file_get_contents($filename)) as $token) { if(!$token->isIgnorable()) { $name = $token->getTokenName(); switch($name){ case 'T_NAMESPACE': $getNextNamespace=true; break; case 'T_EXTENDS': case 'T_USE': case 'T_IMPLEMENTS': //case 'T_ATTRIBUTE': $skipNext = true; break; case 'T_ABSTRACT': $isAbstract = true; break; case 'T_CLASS': case 'T_TRAIT': case 'T_INTERFACE': if($skipNext) { $skipNext=false; } else { $getNext = strtolower(substr($name, 2)); } break; case 'T_NAME_QUALIFIED': case 'T_STRING': if($getNextNamespace) { if(array_filter($rs)) { throw new \Exception(sprintf('Namespace mus be defined first in %s', $filename)); } else { $rs['namespace'] = $token->text; } $getNextNamespace=false; } elseif($skipNext) { $skipNext=false; } elseif($getNext) { if(in_array($token->text, $rs[$getNext])) { throw new \Exception(sprintf('%s %s has already been found in %s', $rs[$getNext], $token->text, $filename)); } if($isAbstract) { $isAbstract=false; $getNext = 'abstract'; } $rs[$getNext][]=$token->text; $getNext=null; } break; default: $getNext=null; } } } $rs['filename'] = $filename; return $rs; }
I need to process a CSV file in database (MySql using LOAD DATA INFILE)), while the code is working fine but it works only with file that is already on my apache server (where php is installed). Is there any way (Java/Ajax or anything) that I can prompt user to select a file from any loaction they prefer including there desktop?? Thanks in advance!! Hi, I am struggling with a form in php. I am trying to add a form by using the include function. I want to include thsi form on all pages so it would be very useful if I can save the current page name somewhere so that I can use to validate the form. For example, this is the form I am trying to include. <?php if(!empty($errors)) { if(isset($errors['sendError'])) { echo '<p><strong class="error">There was a problem with our system please contact us directly.</strong></p>'; } else { echo '<p><strong class="error">Please check the form below for errors.</strong></p>'; } } ?> <form action="index.php" method="post" id="form1"> <p> <label><?php if(isset($errors['name'])) { echo '<span class="error">'; } ?>Name<font color="red">*</font>: <?php if(isset($errors['name'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['name']; ?>" name="name" size="60" align="right" style="background:#EEF5A4" /> <label><?php if(isset($errors['company'])) { echo '<span class="error">'; } ?>Company: <?php if(isset($errors['company'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['company']; ?>" name="company" size="60" align="right" /> <label><?php if(isset($errors['phone'])) { echo '<span class="error">'; } ?>Phone Number: <?php if(isset($errors['phone'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['phone']; ?>" name="phone" size="60" align="right" /> <label><?php if(isset($errors['email'])) { echo '<span class="error">'; } ?>Email<font color="red">*</font>: <?php if(isset($errors['email'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['email']; ?>" name="email" size="60" align="right" style="background:#EEF5A4" /> <label><?php if(isset($errors['enquiry'])) { echo '<span class="error">'; } ?>Enquiry: <?php if(isset($errors['enquiry'])) { echo '</span>'; } ?></label> <textarea id="search1" id="complete" textarea name="enquiry" rows=4 cols=40 value="<?php echo $form['enquiry']; ?>" name="enquiry" size="60" align="right"></textarea> </p> <p> <input type="submit" class="formbutton" value="Submit" /> <input type="reset" class="formbutton" value="Reset" /> </p> <p><font color="red">*</font> Denotes a required field</p> </form> Because I am going to use this form on all pages, I would like it to include whatever the filename is rather than index.php in the first line of the form so that when the user clicks submit, it will stay on the same page but validate the form based on the mandatory fields. I don't know if the question is clear. I would very much appreciate any help at all. Thank you very much. Hi everyone. I have a small problem. I have a database that shows student images, in the format of 1234.jpg but the file name extension is in both upper case and lower case. My server OS is linux ubuntu. apache2 php5. Linux see these as 2 different file so will not show the upper case ones. 1234.JPG What i have already is working but for lower case only, i need something to detect when the extension is in uppercase and change accordingly. This is what i have now that works for lower case only. <img src=../images/mbr_images/<?php echo H($mbr->getBarcodeNmbr());?>.jpg height=150 width=100 border=1px </img This is what i have tried but gives me a filename of "1234jpg" see the "." is missing? and is still lower case. <img src=../images/mbr_images/<?php echo H($mbr->getBarcodeNmbr()); $image = jpg; $image2 = JPG; if ($image = $image) { echo $image; } else { echo $image2; };?> height=150 width=100 border=1px </img> can anyone offer any help please? TIA Peter Is there a class out there that validates window filenames? Thank you. I am trying to get the actual filename so that I can attach it to an email. I tried echo $file; but its not giving me anything. Just a blank page. Here's the code that I' working with: $file = date('M-d-Y H:i A'). '.png'; $uri = substr($data,strpos($data,",")+1); file_put_contents('./Collection_Posts/'.$file, base64_decode($uri)); echo $file; exit;
Hi all, I am working on the PHP to fetch the data from the database. I would like to fetch the filename only following by: email1.png email2.png email3.png my_inbox.png
When I try this: $mailbox_sql = 'SELECT * FROM ' . $mailfolder . ' WHERE email_id = ? AND message_id = ?'; $mailbox = $link->prepare($mailbox_sql); $mailbox->execute([$id,$message_id]); // set the resulting array to associative $row = $mailbox->fetch(PDO::FETCH_ASSOC); if (is_array($row)) { $attached = $row['attached_files']; $attached_files_name = explode('attid: ', $attached); }
I am getting this: 0 filename: email1.png 1 filename: email2.png 2 filename: email3.png 3 filename: my_inbox.png
Here is what I have stored in the database: attid: 0 filename: email1.png attid: 1 filename: email2.png attid: 2 filename: email3.png attid: 3 filename: my_inbox.png
Here is what I want to achieve: email1.png email2.png email3.png my_inbox.png
Can you please show me example how I could get the filename when I am fetching the data from the database? Thanks in advance. Edited January 18, 2020 by mark107Hello folks, I am new to the forum. I am having a problem on SBS 2011 creating a ZipArchive with PHP. Although I have specified the filename to create as "myzip.zip" the file created in the temp folder is "myzip.zip.a10860". If I try again immediately the file becomes "myzip.zip.b10860" and then "myzip.zip.c10860". Of course the numbers will change if I wait a few minutes. I have also tried creating the file first with fopen() then closing it and trying the ZipArchive::OVERWRITE. Still the same result I have tried many standard scripts from the net as well as my own very basic script and always the same result. PHP is set up through Fastcgi. Any thoughts would be appreciated. Michael Hi
I am winning I think
I have got the records displayed for the current user logged in so basically they can only see their submitted listings and just working on the edit of them so the current user logged in can update their listing and is all working apart from the update of the images
the images are stored by the file name on the database and then gets moved onto the server so the actual images are not stored on the database only the file names are and the images are moved onto the server, hope that makes sense
what I can't do at the mo is work out how to update the file names of the images on the database and update on the server
I get the following error
Notice: Undefined index: photo on line 209 and line 211
the coding for them lines are below
$pic1= basename($_FILES['photo']['name'][0]); $pic2= basename($_FILES['photo']['name'][1]);The rest of the coding below that is if(!empty($_FILES['photo']['tmp_name'])) { // Number of uploaded files $num_files = count($_FILES['photo']['tmp_name']); /** loop through the array of files ***/ for($i=0; $i < $num_files;$i++) { // check if there is a file in the array if(!is_uploaded_file($_FILES['photo']['tmp_name'][$i])) { $messages[] = 'No file uploaded'; } else { // move the file to the specified dir if(move_uploaded_file($_FILES['photo']['tmp_name'][$i],$target.'/'.$_FILES['photo']['name'][$i])) { $messages[] = $_FILES['photo']['name'][$i].' uploaded'; } else { // an error message $messages[] = 'Uploading '.$_FILES['photo']['name'][$i].' Failed'; } } }The update query is below // save the data to the database mysql_query("UPDATE privatelistings SET listingtitle='$listingtitle', make='$model', model='$model', exteriorcolour='$exteriorcolour', enginesize='$enginesize', fueltype='$fueltype', yearregistered='$yearregistered', transmission='$transmission', mileage='$mileage', nodoors='$nodoors', bodystyle='$bodystyle', price='$price', photo='$pic1', photo1='$pic2' WHERE id='$id'") or die(mysql_error());I am going to be updating to mysqli just want to get it working first My HTML form coding is below <form action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div> <strong>Listing Title: *</strong> <input type="text" name="listingtitle" value="<?php echo $listingtitle; ?>"/> <br/> <strong>Make: *</strong> <input type="text" name="make" value="<?php echo $make; ?>"/> <br/> <strong>Model: *</strong> <input type="text" name="model" value="<?php echo $model; ?>"/> <br/> <strong>Exterior Colour: *</strong> <input type="text" name="exteriorcolour" value="<?php echo $exteriorcolour; ?>"/> <br/> <strong>Engine Size: *</strong> <input type="text" name="enginesize" value="<?php echo $enginesize; ?>"/> <br/> <strong>Fuel Type: *</strong> <input type="text" name="fueltype" value="<?php echo $fueltype; ?>"/> <br/> <strong>Year Registered: *</strong> <input type="text" name="yearregistered" value="<?php echo $yearregistered; ?>"/> <br/> <strong>Transmission: *</strong> <input type="text" name="transmission" value="<?php echo $transmission; ?>"/> <br/> <strong>Mileage: *</strong> <input type="text" name="mileage" value="<?php echo $mileage; ?>"/> <br/> <strong>Number of Doors: *</strong> <input type="text" name="nodoors" value="<?php echo $nodoors; ?>"/> <br/> <strong>Body Style: *</strong> <input type="text" name="bodystyle" value="<?php echo $bodystyle; ?>"/> <br/> <strong>Price: *</strong> <input type="text" name="price" value="<?php echo $price; ?>"/> <br/> <strong>Photo One:</strong> <input type='hidden' name='size' value='350000'><input type='file' name='photo[]'> <br> <strong>Photo Two:</strong> <input type='hidden' name='size' value='350000'><input type='file' name='photo[]'> <br> <input type="submit" name="submit" value="Submit"> </div> </form>sorry was not sure what other I need to show, so you guys get the idea? If it would be just CSS I would just put " " around the url, however this is a php script. Here's the line:
<li style="background: url({img server_id=$aSlidePhoto.server_id path='photo.url_photo' file=$aSlidePhoto.destination suffix='_175' title=$aSlidePhoto.title return_url=true}); width: 175px; height: 130px;">It works for all images except, for example: myimage (1).jpg What's the fix for such case? How come my$_SERVER['PHP_SELF'] echos the filename.php I have a rewrite rule and i need it to echo http://site.com/file/321 instead of filename.php?id=321 Help! Godaddy wont tell me why its doing that |