Jump to content

akshay

Members
  • Posts

    50
  • Joined

  • Last visited

    Never

Everything posted by akshay

  1. Hello. Is there a simple code to find status of a download. For example, after I launch a file download with php, I want to find status of that download (whether its complete or not), just like file hosting/sharing sites do. And if its "in progress", I want to prevent parallel downloading... I don't understand much of header() commands, except header("location..."); "refresh:... So, if you can assist me with it (like commenting what each command does, I'd appreciate) Thanks
  2. Hello. I wrote this code for a hosting site... It works fine, but if the file status is set to "private" / "password" is turned on, the user is redirected to 404 page (File not found) <?php include_once("../sql.php"); session_start(); $sessid=session_id(); global $f; $f=$_GET['f']; //check for login: if(isset($_COOKIE['token'])) { $emailhash=$_COOKIE['token']; $loginq="SELECT * FROM users WHERE emailhash='$emailhash' AND status='active' "; $loginres=mysql_query($loginq,$conn) or die(mysql_error()); if(mysql_num_rows($loginres)==1) { $fname=mysql_result($loginres,0,'fname'); $lname=mysql_result($loginres,0,'lname'); $email=mysql_result($loginres,0,'email'); $loginmsg="<font face=\"Arial\" color=\"#1b1463\">Welcome <b>$fname $lname !</b> | <a href=\"http://fict-site-anything.com/logout.php\" target=\"_blank\">Logout</a></font>"; } else { setcookie("token","",time()-60,"/","fict-site-anything.com",0); //unset cookie $loginmsg="<font face=\"Arial\" color=\"#1b1463\">You are not logged in | <a href=\"http://fict-site-anything.com/login.php\" target=\"_blank\">Login</a> | <a href=\"http://fict-site-anything.com/acctypes.php\" target=\"_blank\"><b>Sign Up!</b></a></font>"; $email=""; } } else { $email=""; $loginmsg="<font face=\"Arial\" color=\"#1b1463\">You are not logged in | <a href=\"http://fict-site-anything.com/login.php\" target=\"_blank\">Login</a> | <a href=\"http://fict-site-anything.com/acctypes.php\" target=\"_blank\"><b>Sign Up!</b></a></font>"; } $sqlquery="Select * from files where fileid='$f' "; $result=mysql_query($sqlquery,$conn) or die(mysql_error()); if (mysql_num_rows($result) > 0 ) { $filename=mysql_result($result,0,'name'); $realpath=mysql_result($result,0,'realpath'); $downloads=mysql_result($result,0,'downloads'); $ext=mysql_result($result,0,'ext'); $size=filesize($realpath); if ($size>=1000 && $size<1000000) { $sizeunit="KB"; $size=round($size/1000,2); } elseif ($size>=1000000 && $size<1000000000) { $sizeunit="MB"; $size=round($size/1000000,2); } elseif ($size>=1000000000 && $size<1000000000000) { $size=round($size/1000000000,2); $sizeunit="GB"; } elseif ($size>=1000000000000 && $size<1000000000000000) { $size=round($size/1000000000000,2);; $sizeunit="TB"; } else { $sizeunit="bytes"; } $status=mysql_result($result,0,'status'); $filepw=mysql_result($result,0,'password'); // $privacy=mysql_result($result,0,'privacy'); <-- Depreciate & Replace by 'status' if($filepw!='' || $filepw!=NULL) { $filepwenc=md5(md5($filepw)); if(!isset($_GET['key']) || $_GET['key'] != $filepwenc) { header("location: http://fict-site-anything.com/dl/checkpass.php?f=$f&sessid=$realsessid"); exit; } } if($status=='private') { $privateq="SELECT * FROM files WHERE status='private' AND email='$email' AND fileid='$f' "; $privateq_res=mysql_query($privateq,$conn); if(mysql_num_rows($privateq_res)==0) header("location: http://fict-site-anything.com/error.php?msg=private"); } //if status private, ends. if($status!='active' && $status!='private') { header("location: http://fict-site-anything.com/error.php?msg=$status"); exit; } } else { header("location: http://fict-site-anything.com/error.php?err=404"); } A bug-fix / suggestion is really appreciated! Thank you!
  3. Hello. I understand logic behind foreach ($_POST as $key) loop but what about: foreach ($_POST as $key => $value) I mean wha does => imply. Please explain with an example. Thank you!
  4. Hello. I used this code for launching a download... It doesn't seem to work fine. The download is launched but the file is always 26 bytes long and reads (if opened with text editor) "<h1>An error has occured</h1>". Please help Also Where can I get a LIST & Explanation of complete header() function. I mean what all I can do with header() (all commands) ? <?php /* include_once("../sql.php"); session_start(); $realsessid=session_id(); if (!isset($_GET['f']) || !isset($_GET['dlpath']) || !isset($_GET['sessid']) || !isset($_GET['dlpathtok'])) { header("location: http://mintload.com/dl/?f=".$_GET['f']); } else { if(($_GET['sessid'])!=$realsessid || $_GET['dlpathtok']!=md5($_GET['dlpath']) ) { header("location: http://mintload.com/dl/?f=".$_GET['f']); exit; } } $f=$_GET['f']; $dlpath=$_GET['dlpath']; //increment downloads by one...! $dinc="UPDATE files SET downloads=downloads+1 where fileid='$f' "; $dinc_res=mysql_query($dinc,$conn) or die(mysql_error()); */ //----------------------------------------------::: MAIN CODE BEGINS HERE::: //Launch dl: //$dlpath = file location if (file_exists($dlpath) && is_readable($dlpath)) { // get the file size and send the http headers $size = filesize($dlpath); $filename=basename($dlpath); header('Content-Type: application/octet-stream'); header('Content-Length: '.$size); header('Content-Disposition: attachment; filename='.$filename); header('Content-Transfer-Encoding: binary'); $file = @ fopen($dlpath, ‘rb’); if ($file) { // stream the file and exit the script when complete fpassthru($file); exit; } else { echo "<h2>An error occured!</h2>"; } } //file_exists ends else { echo "File does not exist!"; } ?>
  5. Hello. I wanted to integrate PayPal payment gateway on my website (So as if payment is complete, user should be allowed to access premium pages) Please see the code here: https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_admin_IPNImplementation I've understood much of it, except the headers. Also, It says the code must collect HTTP Codes (Example: 400,200,etc.) How to do that? And also, Does MY site require SSL/TLS? Thank you. Also,
  6. Hello. I was just wondering how to pass a URL as a variable with $_GET method. For example a redirect page... Example: $url="http://yoursite.web/ref/?id=2948&name=jon&abc=xyz" $code="12345" Now when I link the two variables , the resulting link might look like : http://mysite.web/redirect.php?code=12345&url=http://yoursite.web/ref/?id=2948&name=jon&abc=xyz or, ?url=......&code=... The problem is that the "&" and "?" might interfere with each other and may deliver no result on the page. I think the solution is converting the special characters into HTML, what do you say, encryptions? Like " " (space) = %20 and "/" (slash) is %2F or %3F How to do so? Any other solution welcome. Thanks.
  7. Hello. 1. I've searched all the pages, but couldn't find any simple code for "PHP Upload Meter". I want a simple upload meter that tracks a file's upload's progress. Though a graphical progress bar is preferred, but even if I replace it with some "Loading..." GIF, I still need the size uploaded, say : 415KB/500 KB ... 417KB/500KB and so on... If you have a simple code even for a "text" upload meter as explained above, kindly let me know. 2. Can't we make a countdown timer with PHP that updates every second? Will I have to use javascript? In case, you got a clue please let me know. Thank you.
  8. Hello. I was wondering in case I've to switch my site to "maintenance mode", what do I do either with PHP / .htaccess such that any page browsed on my site say http://mysite.web/dir/file.ext redirects to http://mysite.web/maintainence.php or simply /index.php ? Because, for sure I'm not going to edit each page / directory and add header code. I just want to redirect the visitor to "under maintenance" page or home page (that reads "under maintenance") when he/she accesses any page/directory. Thank you Akshay
  9. Thanks a lot to both of you!!!! Akshay
  10. Hello. I'm trying to make an online booking calendar. I used following code for generating PHP calendar: (code works fine! u may skip reading this one) <?php $date=time(); $day=date('d',$date); $month=date('m',$date); $year=date('Y',$date); $first_day=mktime(0,0,0,$month,1,$year); $title=date('F',$first_day); $day_of_week=date('D',$first_day); switch($day_of_week) { case "Sun": $blank=0; break; case "Mon":$blank=1; break; case "Tue": $blank=2; break; case "Wed":$blank=3; break; case "Thu": $blank=4; break; case "Fri":$blank=5; break; case "Sat": $blank=6; break; } $days_in_month=cal_days_in_month(0,$month,$year); //0 is Calendar Number, Example: Gregorian..,etc.. php.net: $num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31 echo "<table border=1 width=294>"; echo "<tr><th colspan=7>$title - $year</th></tr>"; echo "<tr>"; $dz=array("S","M","T","W","T","F","S"); foreach($dz as $value) { print "<td width=42> $value </td>"; } echo "</tr>"; $day_count=1; echo "<tr>"; while ($blank>0) { echo "<td></td>"; $blank--; $day_count++; } $day_num=1; while ($day_num<=$days_in_month) { echo "<td> $day_num </td>"; $day_num++; $day_count++; if($day_count>7) { echo "</tr><TR>"; $day_count=1; } } while($day_count>1 && $day_count<7) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> But, what about this: I want in the same calendar, if the dates are 1st,6st,7th,8th (Examplary) , i.e. one from $working_days array, those numbers should be printed in green color and hyperlinked to /book.php?day=(day of month number). But, this code prints all numbers in month as 1,6,7,8 and loops the calendar nonstop! Code: <?php $date=time(); $day=date('d',$date); $month=date('m',$date); $year=date('Y',$date); $first_day=mktime(0,0,0,$month,1,$year); $title=date('F',$first_day); $day_of_week=date('D',$first_day); switch($day_of_week) { case "Sun": $blank=0; break; case "Mon":$blank=1; break; case "Tue": $blank=2; break; case "Wed":$blank=3; break; case "Thu": $blank=4; break; case "Fri":$blank=5; break; case "Sat": $blank=6; break; } $days_in_month=cal_days_in_month(0,$month,$year); //0 is Calendar Number, Example: Gregorian..,etc.. php.net: $num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31 echo "<table border=1 width=294>"; echo "<tr><th colspan=7>$title - $year</th></tr>"; echo "<tr>"; $dz=array("S","M","T","W","T","F","S"); foreach($dz as $value) { print "<td width=42> $value </td>"; } echo "</tr>"; $day_count=1; echo "<tr>"; while ($blank>0) { echo "<td></td>"; $blank--; $day_count++; } $day_num=1; $working_days=array(1,6,7,; while ($day_num<=$days_in_month) { foreach($working_days as $wd) { if($day_num=$wd) { echo '<td><a href="/book.php?day='.$day_num.'"><font color="darkgreen"> '.$day_num.' </font></a></td>'; } //end if else { echo "<td> $day_num </td>"; } //end else } //end foreach $day_num++; $day_count++; if($day_count>7) { echo "</tr><TR>"; $day_count=1; } } while($day_count>1 && $day_count<7) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> Please help. All i need to do is, if dates are from the array/already specified; print them in green with a hyperlink : /book.php?day=(that day of month, in numbers) Thank you Akshay
  11. Hey. Errors occur no more by array_read.php din't show up a single selected product! Pls. help. Thanks.
  12. yea, Don;t use <br> in echo. Leave an optional space for a simple view. Hope it Helps Akshay aka aXe
  13. Oh. I used to wonder a lot about such links too! It's nothing but data posted using GET method. It can be retrived using $_GET[variable] Example: If in a form: <form method="GET" action="url.php"> ... ... <input type="text" name="email"> ...</form> would submit /[email protected] on URL.php, we'd then be able to use this email, like print $_GET; For any help you may msg. me. Hope it helps Akshay
  14. Hello. My codes for these pages produce errors: array.php errors: Warning: array_merge() [function.array-merge]: Argument #1 is not an array in D:\wamp\www\test\session\array.php on line 12 Warning: array_unique() [function.array-unique]: The argument should be an array in D:\wamp\www\test\session\array.php on line 12 array_read.php errors: Warning: Invalid argument supplied for foreach() in D:\wamp\www\test\session\array_read.php on line 12 Basically, I'm trying to add products to cart and display them. Simple! Then, why so many errors? Also, I didnt understand what serialize() and unserialize() are for, despite referring to php.net manual My coding: array.php: <?php session_start(); //Turn off Notices $ebits = ini_get('error_reporting'); error_reporting($ebits ^ E_NOTICE); //Notices Turned OFf if(isset($_POST['form_products'])) { if(!empty($_POST['form_products'])) { $products=array_unique(array_merge(unserialize($_SESSION['products']),$_POST['form_products'])); } $_SESSION['products']=serialize($products); print "Your products have been saved!"; } ?> <html> <body> <form method="post" action="<?php print $_SERVER[php_SELF] ?>">; <p>Select some products:</p> <select name="form_products[]" multiple size=3> <option>iBall Li'l Book 1710</option> <option>Lenovo S10 Netbook</option> <option>ASUS Netbook</option> </select><br><br> <input type="submit" value="Add to Cart"></form><br> <a href="array_read.php">Array Read</a> </body></html> array_read.php : <?php //Turn off Notices $ebits = ini_get('error_reporting'); error_reporting($ebits ^ E_NOTICE); //Notices Turned OFf session_start(); if(isset($_SESSION['products']) && !empty($_SESSION['products'])) { echo "Your cart:<ol>"; foreach($_SESSION['products'] as $p) { print "<li>$p</li>"; } print "</ol>"; } echo '<br><br><a href="/test/session/array.php">Back to Product Choices</a>'; ?> Thanks a lot! Akshay
  15. Hello. I've noticed this strange path problem. While programming on a PHP server, the path is always '/' (default directory), even if your pages are located in /directory/subdir Example, I had put <iframe src="/ifr_marquee/"></iframe> on the page present in 'web' dir. as: /web/index.php As per the logic, the path of iframe picked by PC should be: /web/ifr_marquee however, it picks /ifr_marquee from 'main' directory. and I'll have to specify full path, i.e. /web/ifr_marquee to tell the server about location of directory. Why is that so? had the page extension been HTML, everything would have worked fine, then why with PHP? Also, other files present in /web/ folder had ../xyz/ (i.e. xyz in main directory). Does that mean ../xyz in a directory, on PHP server = /xyz ? I know, I'm not being very clear. I just want to know why it happens? And Can it be overcome with include_path() ? Thank you! Akshay
  16. Thanks a lot man!
  17. Hello. I need help regarding foreach loop. php.net manual says, foreach means, FOR each element of AN ARRAY, do the following... But, can someone explain me the logic used in these code snipplets (only for foreach statements) : PHP Upload Script: <?php $file_dir="d:/wamp/www/test/files"; foreach($_FILES as $file_name => $file_array) { //what does this mean? ONLY the foreach statement print "Path: ".$file_array['tmp_name']."<br>"; print "Name: ".$file_array['name']."<br>"; print "Type: ".$file_array['type']."<br>"; print "Size: ".$file_array['size']."<br>"; $flnm=$file_array['name']; if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], "$file_dir/$flnm") or die("Error!"); print "Upload Successful!"; } } ?> and another one is simpler (printing date values using php getdate() function) : $date_array=getdate(); foreach($date_array as $key=>$val) { //explain this print "$key = $val<BR>"; } // I simply use this code: print "<BR><BR>The Date is:<br>"; print $date_array['mday']." "; print $date_array['month']." "; print $date_array['weekday']. " "; print $date_array['year']." ";
  18. Thank you!
  19. Hello. How to read in between string with separatation characters... To simplify: Example: $string="username ^ password ^ email"; $a= //should be equal to text before first ^ in $string, i.e. username $b= //should be equal to text between first ^ and second ^, i.e. password $c = // should be equal to text after second ^, i.e. email Is there a way? what about fseek() ? Thank you
  20. PROBLEM RESOLVED wow... It solved the problem! Thank you!
  21. Hello. Probably, ur captcha is the worst I've ever seen! Php Freaks is great... Please use a new captcha... This one is unreadable, and after error occurs "char. not matching the img.", one cant even retrieve a new captcha image! Thank you.
  22. Hello. I'm reading Sams - Teach Yourself PHP, mySQL, Apache in 24 hours. It's going great, but... I used this code : select.php : <html>... <form method="POST" action="sql_select.php"> Welcome to KrisShop<br><Br> Name:<input type="text" name="name"><BR> Address & Contact Details: <textarea name="address"></textarea> <Br><Br> Please select the products you wish to buy:<BR><BR> <select name="products[]" multiple> <option>Microwave Oven</option> <option>Apple iTouch</option> <option>Blackberry</option> </select> <Br> <input type="submit" value="♥ Submit ♥"> </form><body> </body> </html> sql_select.php : <?php print "Welcome <b>$_POST[name]</b><p>\n\n"; print "Your address is:<p>\n\n<b>$_POST[address]</b><p>\n\n"; print "Your product choices are:<p>\n\n"; if (!empty($_POST[products])) { print "<ul>\n\n"; foreach ($_POST[products] as $value) { print "<li>$value\n"; } print "</ul>"; } ?> It does print Name and Address properly. But, SELECT element - 'products' are printed with warnings: Example: * Microwave Oven * Blackberry Notice: Use of undefined constant products - assumed 'products' in D:\wamp\www\test\sql_select.php on line 32 Wherever, 'products' variable is used, these warnings (notice) appear with output, I've tried 'products[]' and 'products' too. I tried adding $a=$_POST[products]; and adding $_POST[products] in the entire code by $a, one notice was eleminated, but, another one, next to "foreach" loop still appears. Thank you Best Regards Akshay [attachment deleted by admin]
  23. Password may require digits and alphabets. But, requiring upper-case letters creates confusion!
×
×
  • 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.