Jump to content

ajoo

Members
  • Posts

    871
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ajoo

  1. Hi mac_gyver and Guru Jacques and thanks for your replies ! @ Mac_gyver That itself nailed it. For reasons unknown to me, i was using session_start in verifymail.php. I changed that to sess_start() and things are back to normal. The idea of putting the same initializing code into a file by itself is great. I'll use it. While I have heard of single page websites, I don't know how to implement one. I'll keep in mind to check it soon. A link to a nice tutorial on that would be great ! @Guru Jacques ! I am not really sure about the custom ini settings thingy you mention. I'll look up some user.ini examples to understand that a bit further. I think this was just a bit of an oversight. I don't think my code is making changes to any ini settings, so hopefully none would be overwritten. I would be glad if you can elaborate this a bit more and possibly with a small example. Confused deputy would suit me better ! Thanks loads to you both !
  2. Hi all ! I have an index file which begins as <?php error_reporting(E_ALL); define('INCLUDE_CHECK',true); require_once 'fran_load.php'; session_start(); // works fine with session_start() //sess_start(); // was working fine earlier but is now problematic header("Content-Security-Policy-Report-Only: default-src 'self' img-src 'self' data: https://www.google.com/ https://ajax.googleapis.com/ https://www.gstatic.com/ http://localhost/xampp/franchisee/; report-uri http://localhost/xampp/franchisee/reports/reportcspviolation.php"); // mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqliDriver = new mysqli_driver(); $mysqliDriver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; $timezone = "Asia/Calcutta"; if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone); // set_exception_handler('exception_handler'); . . . and an email activation request page.verifymail.php which begins as <?php error_reporting(E_ALL); session_start(); header("Content-Security-Policy-Report-Only content=default-src 'self' https://www.google.com/recaptcha/ https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/"); define('INCLUDE_CHECK',true); require_once 'fran_load.php'; /* echo "<pre>"; echo $_SESSION['user_token']; echo "</pre>"; exit(); */ $message = ''; $terminate = false; . . . sess_start() is function sess_start() { $session_name = 'sec_session_id'; // Set a custom session name $secure = false; // Set to true if using https. $httponly = true; // This stops javascript being able to access the session id. ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies. $cookieParams = session_get_cookie_params(); // Gets current cookies params. session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); // 0, /, ''. session_name($session_name); // Sets the session name to the one set above. session_start(); // Start the php session } Earlier all seemed to work well, but suddenly there is an issue. On submitting the form with action = "verifymail.php" which sends from the index.php to verifymail.php, i find that the $_SESSION variable is blank, thereby not maintaining the session on that page. I am setting some session variables in the form before it is submitted. I commented out sess_start() on index.php and simply used session_start() and all seems to work fine. I would like to use sess_start, since I am setting the cookie timeout and other values therein, if I can. Please can someone suggest why this is happening and how it can be overcome to use sess_start(). Thanks all.
  3. Hi Guru Jacques ! Thanks for the reply or I would have continued struggling with this. Thanks loads.
  4. Hi all ! This snippet below, with an older version of jquery, namely 1.7.2 works fine with Internet Explorer 8 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script> while this one below, the newer version, namely 3.1.1 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.js"></script> gives the Object Expected error. My login page with a slider login panel renders but with errors, it says, and the slider does not function. It does not slide down. The two script lines are exact same except for the version diff. Please suggest if and how may I resolve this issue. Thanks loads everyone.
  5. The following does it :- ob_start(); imagejpeg($dst_img); $imagedata = ob_get_contents(); ob_end_flush(); Thanks for the pointer mac_gyver
  6. Hi all, The following bit of snippet displays a resized jpeg. $dst = imageCreateTrueColor($nwidth, $nheight); imageCopyResampled($dst, $src, 0, 0, 0, 0, $nwidth, $nheight, $ix, $iy); imagejpeg($dst); Is there a simple, direct way to extract image data (BLOB) from this without actually saving the imagejpeg($dst) to a file first and then reading it back again ? Thanks all !
  7. Hi Guru Barand ! I tried that before I asked but i was getting an error. It said something like - the $filename ('path/to/file') should be a resource and not a string. - but eventually it worked. Thank you.
  8. Hi all, Below is the last bit of code that loads an image from a local machine, resizes it and displays the resized image on a screen. imagepng($dst); // displays the resized image imagedestroy($src); imagedestroy($dst); What I want to do now is to save the resized image on the server. How may I do that ? Any help is much appreciated. Thanks all.
  9. Hi all ! The following code snippet taken from the php manual does not display the png image. The similar code for jpeg images works fine. The server support for png images is enabled on my server. function LoadPNG($imgname) { /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/png'); $img = LoadPNG('bogus.image'); imagepng($img); imagedestroy($img); Please can someone explain how to get this working? Thanks all !
  10. Hi all ! I realized that the code snippet requires to make a db connection. DB.php is not present. Anyways , the snippet above works just fine. It's just that I am unable to constrain it's size of the displayed image (after reading the stored image on the server) to the one I want. I have seen similar code on the net but that does not use the readfile function. I think it has to do with this function that the image size is not being constrained. <img width="xxx" height="yyy" ... doesn't seem to work either. Is there any way to constraint the size of the displayed image without actually resizing it ? Thanks all !
  11. Hi all ! I have been experimenting with a bit of code that uploads file to the server. The image is previewed once selected and can then be uploaded. The uploaded image is then selected and displayed. Here is the code usp5.php <?php error_reporting(E_ALL); require_once 'DB.php'; $uploaddir = 'D:/xampp/php/internals/uploads/'; # Outside of web root // echo $uploadfile."<br>"; // exit(); if(isset($_POST['upload'])) { $blob = "BLOB"; $filename = $_FILES['userfile']['name']; $filetype = $_FILES['userfile']['type']; $tmp_filename = $_FILES['userfile']['tmp_name']; $uploadfile = tempnam($uploaddir, "upm"); if (move_uploaded_file($tmp_filename, $uploadfile)) { try { $query = "INSERT INTO images (name, original_name, mime_type, images) VALUES (?,?,?,?)"; $stmt = $link->prepare($query); $stmt->bind_param('ssss',$uploadfile,$filename,$filetype,$blob); if($stmt->execute()){ $id=$stmt->insert_id; // get the just inserted id } else{ echo "Error : ".$link->error; } } catch(mysqli_sql_exception $imageException) { if ($imageException->getCode() === MYSQL_ER_DUP_ENTRY) { echo'The filename is already taken, please choose a different name.'; return false; } else { // rethrow exception throw $imageException; } } } if(!is_numeric($id)) { die("File id must be numeric"); } $query = 'SELECT name, mime_type FROM images WHERE id=?'; $stmt = $link->prepare($query); $stmt->bind_param('i',$id); $stmt->execute(); $stmt->bind_result($filename,$type); $stmt->store_result(); $stmt->fetch(); $stmt->free_result(); if(is_null($filename) || count($filename)===0) { die("File not found"); } header("Content-Type: " . $type); // echo "<div class='div2'>"; // works good without the div. Divs cause the binary dump to show instead echo '<img src="'.readfile($filename).'"alt="">'; // echo "</div>"; } ?> <html> <head> <title>File Upload To Database</title> <link class="jsbin" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" > <link rel="stylesheet" type="text/css" media="screen" href="divs.css" /> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script> <meta charset=utf-8 /> </head> <body> <form name="upload" action="#" method="POST" enctype="multipart/form-data"> Select the file to upload: <br> <input type="file" name="userfile" onchange="readURL(this)"; /><br> <br><input type="submit" name="upload" value="Upload"> <div class = "div1"> <img id="image" src="#" alt="load image" /> <!-- This displays the image. --> </div> </form> <!-- <img class="div2" src="'<?php // readfile($filename); ?>'" alt="load image" /> --> <script> function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#image') .attr('src', e.target.result) .width(200) .height(200); }; reader.readAsDataURL(input.files[0]); }else{ alert( "File not selected or browser incompatible." ); } } </script> </body> </html> divs.css .div1 { height:220px; width: 220px; display:block; margin:5px; border:1px solid navy; background-color:#ffffbb; } .div2 { height:350px; width: 350px; display:block; margin-left:1px; border:1px solid navy; background-color:#ffaaff; } img{ max-width: 100%; max-height: 100%; } In the first preview, before upload, a bigger image is automatically reduced to fit into a 200px by 200px due to the width and height set in the jquery. After the image is loaded on the server and is selected using the id of the image, I am unable to fit the same in a div to restrict the size of the image to any arbitrary given dimensions. Kindly help me with that. Is it possible to display both the images simultaneously in two separate divs ? How ? Any security issues in this ? Thanks all !
  12. Hi all ! I have created a fiddle of the issue that I am facing. It has been partially resolved. i.e. the slider now moves uniformally. However in the close position, the slider tab displays the text for the open and close positions simultaneously. I request anyone to try and have a look and suggest a resolve. fiddle: https://jsfiddle.net/ajoo/totym83v/3/ Thanks.
  13. Hmm Hi Guys, experts, Gurus !! More than a 100 views and no response !? Surely this coudn't be that tough a problem to crack !! Or have i done something wrong - like not defined the problem correct or not given the right inputs? Looking forward to some response. Please advise. Thanks !!!!
  14. Hi all, Please find a zipped file with code simulating the slider distortion issue described above. I hope someone will be able to figure out what's going wrong and provide a solution for the same. Thanks all ! slider.zip
  15. Hi all, I request someone to take a look at this, hopefully not a big, CSS issue that is baffling me for some days now. Thanks all
  16. Hi Kicken, Thanks again for the reply and the Twig example. I am sure it will be of great help in helping me learn about templating. I was in the process of checking out the code you sent earlier. However it always goes and dies at the following bit of code:- if (!is_dir($path) || !is_readable($path)){ die('Cannot access '.$path); and gives the following error:- Any suggestions?
  17. Hi all, I have this slider in a project which was working great till I removed a small bit of inline css and tried to put it in an external file. That produced a distortion in the slider as it moves up n down. Earlier the slider tab moved uniformly ( it's size remained the same as it opened or closed). But now the slider becomes smaller as it opens. and comes back to the original size and place as it closes. Further the x in a circle is slightly eaten when the slide tab is in the open state. The HTML that worked great :- <!-- The tab on top --> <div class="tab"> <ul class="login"> <li class="left"> </li> <li>Hello <?php echo isset($user)? $user : 'Guest';?>!</li> <li class="sep">|</li> <li id="toggle"> <a id="open" class="open" href="#"><?php echo isset($id)?'Open Panel':'Log In | Register';?></a> <a id="close" style="display:none"; class="close" href="#">Close Panel</a> </li> <li class="right"> </li> </ul> </div> <!-- / top --> The accomanying CSS: .tab a.open,.tab a.close { height: 20px; line-height: 20px !important; padding-left: 30px !important; cursor: pointer; display: block; width: 100px; position: relative; top: 11px; } .tab a.open {background: url(../images/bt_open.png) no-repeat left 0;} .tab a.close {background: url(../images/bt_close.png) no-repeat left 0;} .tab a:hover.open {background: url(../images/bt_open.png) no-repeat left -19px;} .tab a:hover.close {background: url(../images/bt_close.png) no-repeat left -19px;} Once I removed the in line CSS style = " ..." , show in red in the code, and added the following bit of code in the external css file: .tab a.close { display: none; } the distortion that I have described above, crept in. I am not sure how I can make the slider work perfect as before. Please someone help me overcome this. Thanks all !
  18. Hi ginerjm & kicken, Thank you both for the inputs to this. @ginerjm : I generally do keep my php code at the top and separated from the HTML. The js goes into it's own files. @kicken : I'll go through the code example and revert in sometime. You are correct in all your assumptions. The $rooms values do come from a DB. I just created those variables to simplify the code. What i was looking for was a way of working my example with a templating engine like Twig as you mentioned. I believe, and I may be wrong, that the php values (like the values in the array $rooms) are somehow, through the templating engine mechanism, passed to the HTML and rendered there. I was actually looking for an example of that sort. Still I am very grateful for all your inputs. I'll revert after playing around with the code and hopefully learning something nice ! Thanks.
  19. Hi Destramic, Thanks for the response. Hmm It's a part of an HTML document which I have modified slightly. The php around this bit of code is because of the need to evaluate the value of rooms from a DB. ( not shown here) and then populate the same. It's those values that should be calculated else where ( in the pure php part of the doc ) and then sent thru here. I think that's what templating is able to accomplish. ( That's what I could make out from some of questions involving templates on the forum) The js, ofcourse would go into it's own file. That was just to put together a working example file. if($room === $displayed)echo ""; hmm again there was a session value that was to be echoed here. Something like that I intend to do after learning a bit about templating, Thanks loads !
  20. Hi all, Below is a small example snippet of an enmeshed php, html, css & js program which I think would be an example of bad programming. Using this simple example below can someone please demonstrate how it may be used to separate the code and convert the html into a template. It would be a nice example to learn about templating I think. Thank all. <?php print_r($_POST); $rooms = array(1,2,3,4); $displayed = 2; ?> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#room').change(function(){ $(this).parent('form').submit(); }); }); </script> <?php echo "<div>"; echo "<form id = 'form1' action='#' method='post' > "; echo "<select name='room' id='room'>"; if(isset($displayed)) echo "<option selected>".$displayed."</option>"; $i = 0; while($i < count($rooms)) { $room = $rooms[$i]; if($room === $displayed)echo ""; else echo "<option value = ".$room." > ".$room." </option>"; $i++; } echo "</select>"; echo "<noscript><input type='submit' value='Submit'></noscript>"; echo "</form>"; echo "</div>"; ?>
  21. Hi Guru Jacques, Thank you very much. Upgrading the jquery library to the latest version helped clear all the errors. I am not getting them now. I have implemented the csp across the project - I think. Many thanks to you for informing me about CSP and all the help to complete its implementation. Kind regards
  22. Hi Guru Jacques, No there were errors in firefox as well. I searched for them and found the errors. (see Below in the picture). There may have been even in Internet Explorer, but I did not know where to look for them. I tried but could not find them in IE. . I'll change the jquery version and see where that leads to. I'll revert with the results. Meanwhile does this now change your last answer in any way? Thank loads!.
  23. Hi Guru Jacques, Kicken and all else ! I am still stuck with this. I have tested this in IE and Firefox as suggested by Guru Jacques and It seems that the problem lies in this particular div : <div id="panel"> It somehow gets styling. I don't know how. It showed up in IE and firefox but not in chrome. Please find attached all the jpegs showing the various results. Chrome: IE: ( have never used this before) FIREFOX: ( have never used this before) CODE: ( This is the actual code snapshot. No error in this even though the name says code_err ) I hope these will be good enough to help you ascertain the issue and guide me on how to correct these errors. Thanks loads.
  24. Hi Guru Jacques, Thanks for the reply and the hint. It helped me remove almost all inline css styles but two which are occurring in the jquery.js file. As suggested, I have temporarily disabled the minified js file. I will revert back if I am still unable to figure out which code is causing this issue. Keeping this question open till then. Thanks loads.
  25. Hi Guru Jacques, The flogin error is caused by the code : <a id="close" style="display: none;" class="close" href="#">Close Panel</a> which is a part of the larger block <ul class="login"> <li class="left"> </li> <li>Hello <?php echo isset($_SESSION['user'])? html_escape($_SESSION['user']) : 'Guest';?>!</li> <li class="sep">|</li> <li id="toggle"> <a id="open" class="open" href="#"><?php echo isset($_SESSION['id'])?'Open Panel':'Log In | Register';?></a> <a id="close" style="display: none;" class="close" href="#">Close Panel</a> </li> <li class="right"> </li> </ul> The error must be because of the inline css styling : style="display: none; The class close is a javascript manipulated :- // Collapse Panel $("#close").click(function(){ $("div#panel").slideUp("slow"); }); if I don't use the inline css style "display : none", then it messes up & the open and close button show up together and slide together. I want to keep the slider so how do I fix this? I have tried a couple of things but none seem to work. Please help. Does this also means that I will have to remove all inline css styles and somehow shift them into external css files for the csp to be effective? Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.