There is a way to deal with client closing a browser or just leaving the site. Use javascript and define onUnload() that would call your script via Ajax to notify your server that client is leaving, so your script can update the session table and mark that client as logged-out.
uncle_smith 7 Light Poster
You can keep a list of who is logged in,
or you can use a cookie.A session variable won't do it because each
session would have its own value.
Cookie will not help at all because a second login attempt may come from a different browser.
You just need a database table where you keep the data about logged-in users like username, login_time, browser, ip_address
You can always check against this table before you let a user to login.
Some issues have to be worked out like what if user logged in but then closed his browser. His login details will still be stored in the database while technically he is no longer logged in.
So if a user has not logged out using a logout link, it's hard to know if the user is still on your site or not.
uncle_smith 7 Light Poster
I have the permission to run chown using the command prompt,
so the script that uploading file need to be root before executing
chown.
How do you chmod these files? Are you doing it yourself or do you have a php script that does chmod after the upload automatically?
If it's your php script that doing the chmod, then it means your apache user account does not own the folder where you trying to do the chmod
uncle_smith 7 Light Poster
Like this:
$BbParser = new HTML_BBCodeParser($settings);
$BbParser->setText( $strContent );
$BbParser->parse();
$PrarsedContent = $BbParser->getParsed();
$settings is array of settings
$strContent is your content that contains bbcode and $ParsedContent is the html with all bbcode replaced by html tags
uncle_smith 7 Light Poster
How would i go about making a music uploader / player or were could a get a script that does that? I want the user to be able to listen as well as contribute music to the site..
you can just let users to upload an mp3 file using an html form. You can even allow uploading more than one file at a time.
Then on a server side you need a script that would store the uploaded files in an organized way and add entry of file name and its new location (a path to where it was saved) to database.
The good thing about mp3 files is that they can be streamed from streaming server, so you don't need any extra steps to encode them for streaming.
The last step is to setup a streaming server. There are several open source free streaming servers. I personally worked with 3:
Red5, Darwin (from apple) and Helix from real networks.
all of these support streaming of mp3 files.
The very last step is to embed the HTML code that would start streaming a file. That would depend on which server you choose, every server has some simple instructions on how to embed the HTML code.
I know this probably sounds too complicated.
You can just place a link to mp3 file directly without using any streaming server. That would work too, especially for relatively small mp3 files.
uncle_smith 7 Light Poster
Define 'dangerous'?
Also mime type can easily be forged, so keep that in mind if you plan to rely on mime type to check for potentially dangerous files
uncle_smith 7 Light Poster
Consider using pear class Mail_Mime to generate Mime emails
This class will take care or encoding your email properly, including attachments.
http://pear.php.net/package/Mail_Mime
See how easy it is to send email with attached file:
http://pear.php.net/manual/en/package.mail.mail-mime.example.php
uncle_smith 7 Light Poster
Hi frnds..
i need to know some ajax based small websites....
i mean website designed by using ajax with php....Also send me some urls regarding ajax basics to learn ajax easily.. ....
Correct me if I'm wrong but it looks like this forum uses Ajax for some of the functions.
Many websites use ajax. I also wrote many ajax-based functions for my own CMS that I am working on.
The registration, login form on the site uses ajax, some profile editing use ajax
Take a look at the web-based style editor I wrote using YUI library for front end and php/mysql on backend.
uncle_smith 7 Light Poster
// assuming the string is called "someString" $words = explode(" ", $someString); $index = rand(0, count($words)-1); $choice = $words[$index];
OK
uncle_smith 7 Light Poster
Hi everyone,
I want to use two radio button on a php page when we click on first radio button page will show different form below the radio button and when we will click or select second radio button then i want to show another form on the same php page.
How we can do this. Please help me. This is very urgent for me
Regards
Gagan Kumar
This sounds more like a javascript trick than a php issue.
There are different ways to do this, it depends on how similar these 2 forms are.
I suggest you post this to javascript forum and post more details about these forms. If forms are very different or contain large select options then best way is to use ajax, otherwise you can pre-load the forms and then display different forms depending on which radio button is selected.
uncle_smith 7 Light Poster
Ok, then after the first
$user_check
add this line and see what mysql complains about:
if (!$user_check) {
die('Invalid query: ' . mysql_error());
}
uncle_smith 7 Light Poster
how ould i do this
You may want to try to pass a valid mysql connection link as a second argument to mysql_query function
Carefully :)
Just kidding.
Well, how do you connect to mysql database? Do you have the mysql_connect() function anywhere in your code?
uncle_smith 7 Light Poster
i don't know if this is enough you to help me but looking at this could you tell me what i could do to fix it?
$user_check = mysql_query("SELECT userdb_user_name FROM default_userdb WHERE userdb_user_name='$reciever'"); $user_check = mysql_num_rows($user_check); Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /xx/xx/x/xx/xx/xx/xxxx/xxxxx/htdocs/xxxx/xxx/xxx.php
Your query did not execute.
at least add this check after the $user_check line:
if (!$user_check) {
die('Invalid query: ' . mysql_error());
}
You may want to try to pass a valid mysql connection link as a second argument to mysql_query function
This should be the result of your mysql_connect() function.
uncle_smith 7 Light Poster
Hi All
I am trying to create a page to delete records from a database, but i cannot seem to get the right code in
hereunder please find my code
<?php require_once('Connections/conn.php'); ?>
<?php
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;
}
}
if ((isset($_GET['productID'])) && ($_GET['productID'] != "")) {
$deleteSQL = sprintf("DELETE FROM Products WHERE productCode=%s",
GetSQLValueString($_GET['productID'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($deleteSQL, $conn) or die(mysql_error());
}
mysql_select_db($database_conn, $conn);
$query_delete = "SELECT productID, productCode, productName, productDesc, productPrice FROM tblproducts ORDER BY productID ASC";
$delete = mysql_query($query_delete, $conn) or die(mysql_error());
$row_delete = mysql_fetch_assoc($delete);
$totalRows_delete = mysql_num_rows($delete);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
Product ID <?php echo $row_delete['productID']; ?> Product Code<?php echo $row_delete['productCode']; ?>
<label></label>
Product Name<?php echo $row_delete['productName']; ?>
<input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo …
uncle_smith 7 Light Poster
The only thing is if the description is shorter than 150 chars, this function may cause error because strpos cannot have value of offset that is greater than length of string
you need to first check that strlen($row) > 150
uncle_smith 7 Light Poster
echo "<meta name=\"description\" content=\"".$row{'Name'}." - ". substr($row['Description'],0,strpos($row['Description'],' ',150)) ."\">\n";
I think that this will break the string at the first whitespace after 150 characters
anyone seen the fingers crossed icon :)
Sorry, my mistake, for some reason I thought that strrpos was used, now I see it is strpos, so everything should work
uncle_smith 7 Light Poster
Apache already logs the access to your image (image view)
All you have to do is configure apache to log access to certain files (like images) to a database instead of to the normal access log.
If you have control over your server, then install something like mod_log_sql and configure it accordingly.
I've done exactly that for my image site, I can post instructions if you need.
uncle_smith 7 Light Poster
as i`m creating a social network website,i would like to inhance members to upload photos to their personal albums.
So i dont know how to get started,is there a free script i can use or somebody to explain to me what i need to do inorder to fulfill my needs.
Also i will appreciate if you can tell me how much Space is needed for Server with a websites of this type(social network website).
This is a very complicated topic, there are just too many possible ways to do this.
First - decide where you want to store your uploaded images - in database as binary data or in the file systems and only store the paths to images in the database.
Second - usually scripts that allow image uploads also implement a thumbnailing feature where a small copy of image is automatically created and store somewhere separately (thumbnail) So you will also have to implement this.
Third - if an image dimension is too large to fit in a normal web page the image should also be resized to something like 600px max width. You should do that. Then another question - if you resize a very large image, do you still want to store the original or not?
Another question - do you want to add a feature to make sure images 'private' meaning to restrict view access to image to only certain users? This is yet another feature you may need …
uncle_smith 7 Light Poster
Hi,
I am making php from.Everhting is working fine.I am receving result as below.I want to space before Tel no.Please be advice how i can do. Thank you.
---------------------------------------------------
Email Result
--------------------------------------------------
General Info Request
Name: Khan1665 Bloor Street
Mississauga
L4X3T4
Tel:647-290-0000
Email: hanyon@gmail.comBest Time To Contact:11am
Message is:
Hi,
---------------------------------------------------<?php $name=$_POST['name']; $phone=$_POST['phone']; $email=$_POST['email']; $contact_time=$_POST['Contact_Time']; $address=$_POST['address']; $city=$_POST['city']; $postal=$_POST['postal']; $message=$_POST['message']; if($message=="") { $message="<b>no message</b>"; } else { $message="<b>Message:</b><br>".$message; } $emailBody ="<HTML>\n" ."<head><title></title></head><body>\n" ."<table bordercolor=red border=\"1\" cellspacing=0 cellpadding=0>\n" ."<tr><td bgcolor=\"#e9e8d6\" colspan=2 align=center><h3>General Info Request</h3></td></tr>\n" ."<tr><td bgcolor=\"#ffffa0\" style=\"border:solid 1px #666666;\"><b>Name:</b>$name</td> <tr><td bgcolor=\"#ffffa0\" style=\"border:solid 1px #666666;\"><b></b>$address</td> <td bgcolor=\"#ffffa0\" style=\"border:solid 1px #666666;\"><b></b>$city</td></tr>\n" ."<tr><td bgcolor=\"#d6d68c\" style=\"border:solid 1px #666666;\" colspan=2><b></b>$postal</td></tr>\n" ."<tr><td bgcolor=\"#ffffa0\" style=\"border:solid 1px #666666;\"><b>Tel:</b>$phone</td></tr>\n" ."<tr><td bgcolor=\"#d6d68c\" style=\"border:solid 1px #666666;\"><b>Email:</b>$email</td> <td bgcolor=\"#d6d68c\" style=\"border:solid 1px #666666;\"><b>Best Time To Contact:</b>$contact_time</td></tr>\n" ."<tr><td bgcolor=\"#ffffa0\" style=\"border:solid 1px #666666;\" colspan=2>$message</td></tr>\n" ."</table></body></html>"; $emailTo = '"" <info@land.ca>'; //Enter your email instead of email@yourdomain.com $emailSubject = "FREE DEMONSTRATION"; $emailSubject = preg_replace('/[\x00-\x1F]/', '', $emailSubject); $emailFrom = $email;//from email $emailFrom = preg_replace('/[\x00-\x1F]/', '', $emailFrom); $emailHeader = "From: $emailFrom\n" . "Reply-To: $emailFrom\n" . "Return-Path: $emailFrom\n" . "X-Sender: $emailFrom\n" . "X-Mailer: PHP\n" . "X-Priority: 3\n" . "MIME-Version: 1.0\n" . "Content-Type: text/html; charset=\"ISO-8859-1\"\n" . "Content-Transfer-Encoding: base64\n" . "\n"; $emailBody=chunk_split(base64_encode($emailBody)); mail($emailTo, $emailSubject, $emailBody, $emailHeader); # Confirmation Email to User $confEmailTo =$email;//from email $confEmailTo = preg_replace('/[\x00-\x1F]/', '', $confEmailTo); $confEmailSubject = "Confirmation "; $confEmailSubject = preg_replace('/[\x00-\x1F]/', '', $confEmailSubject); $confEmailBody = "Hello $fname,\n" . "Thanks for your recent enquiry . We have received your message, we will contact you …
uncle_smith 7 Light Poster
Hi am currently new to php i know all the basics etc but wanting to learn to do bigger more complicated things can anybody reccomend any gud software or books or anywhere could have help learning any help would be appreciated fanx
Depends on what you call basic things.
Do you know OOP in php? that's the thing you must know these days.
I highly recommend this book:
Object-Oriented PHP: Concepts, Techniques, and Code
This book gave me a good basic but solid understanding of OOP in php, from there only daily experience writing code will help you become a better programmer
uncle_smith 7 Light Poster
Hello guys!
I hope you don't mind me posting so quick again. I am struggling or better don't seem to have proper idea about what to do here. I want to make a simple birthday reminder. I have got a list of people in my database and I log in using my id. All I want to do is to display a list of person and if they have got a birthday within the next seven days, display a notification.
I have written a simple function to do that but it doesn't work in the way I want and I can see the prob lies mainly with the month. Is there anything else I can do? Any ideas/help or even link to some tutorials will be gratefully appreciated.
Warm Regards
6pandn21function CalculateAge($BirthDate) { list($Year, $Month, $Day) = explode("-", $BirthDate); $YearDiff = date("Y") - $Year; $MonthDiff= date("m") -$Month; $DayDiff = date("d") - $Day; if ($DayDiff < 8 && $MonthDiff == 0) { $message = " ... this persons's birthday is within the week! <br />";} else {$message = "There is no birthday's within 7 days";} return $message; }
Are you getting any errors? What do you mean does not work?
Are you sure all birthdays are stored in the database in the format
like YYYYY-MM-DD (1980-01-20)?
Also, you have to realize that if my birthday is on Jan 2 (for example, meaning in the first 6 days of the month), then you function will not work because …
uncle_smith 7 Light Poster
I'm actually trying to embed a flash within a form and then on submit, to call the flash function and retrieve data out to php.
I was hoping to achieve something similar to http://www.dracon.biz/contacts.php but have no idea how they do the form passing, how it works.
I looked at their site. I dont think they are doing any time of calls from flash to php. What you see is a normal html form, then onsubmit (or onclick on submit button) javascript replaces some html with a new html snippet that contains a flash movie.
OK, the only thing they may have to do in php is to generate the flash movie that contains the captcha text. This probably had to be done on the server in order to keep track what captcha text they gave you. But again, this effect can be acheived even without the server, the captcha text could have been generated when the form originally is generated then a javascript can interact with flash movie to add the value of patcha text there.
uncle_smith 7 Light Poster
print $thearray[0]; //first print $thearray[count($thearray)-1]; //last // because the index starts with zero
In php the easier way to get the last element is to use end($arr)
diafol commented: Class +3
almostbob commented: Thanks, much simpler +1
uncle_smith 7 Light Poster
Hi,
I have the following peice of code which pulls data from a database:
$rsfeed = mysql_query("select Title from Abstracts where (ID = '12'));
$thearray = mysql_fetch_row($rsfeed);I can print the title using:
print $thearray[0];but theactual resultset is more then 1 row, and what i need to do is print the first row ($thearray[0]) and the last row, how do i modify the above code to achieve that?
thanks
First off:
$rsfeed = mysql_query("select Title from Abstracts where (ID = '12'));
you dont need a parantesise (ID = '12')
just use:
$rsfeed = mysql_query("select Title from Abstracts where ID = '12');
Second, if the ID is unique in your table Abstract, then you will only get 1 row anyway.
If ID is not unique, then your will get many rows that have the same ID = 12
in which case you would reference the first row as $rsfeed[0]
and the last row as end($rsfeed);
uncle_smith 7 Light Poster
Hi
i am trying to output data the way i want but just cant get it to go in the right place. The code i have used is:
for($i=$n_start;$i<=$n_end;$i++)
{echo "<img src='{$products[$i]}' width='100' height='100'>";
echo "<tr>{$products[$i]}</tr>";
echo "<tr>{$products[$i]}</tr>";
echo "<tr><input type='text'
name='item{$products[$i]}' value='0'
size='5'></tr>";}
As you can see the data is output for each item until the loop ends. For each item the data is output correct. However when the data for the next item is output, the next item is output below the previous item. I want the data for the next item to be output on the right hand side of the previous item. How do i do this? Do i need to use a table or something because i cant see how it will work when using this loop??
Thanks.
Not sure I understand exactly what you want but I think you mean you want the next item in the loop to be shown in the next column of table instead of the next row.
If that's the case, then don't include <tr> inside your loop
change the <tr> to <td>
then just before the for loop add echo '<tr>';
and just after the end of loop add echo '</tr>';
uncle_smith 7 Light Poster
hello
I've got two tables that I want to be connected(let's call the A and B), so I made a third table. In table A and B i got two primary keys a_id and b_id. Now I create the third table named AB. Inside that I create ab_id as primary and two foreign keys with the names a_id and b_id..... all is all good right now, working fine.
Now to the issue, what should I write in the code to get example ab_id 1 to show all it's information. And by all information I mean all the info that a_id and b_id have in their tables. You get what I'm looking for here?
Does this require some kind of JOIN?
SELECT a.id as a_id,
a.something_else,
b.id as b_id FROM a, b, c
WHERE c.a_id = a.id AND c.b_id = b.id
AND c.id = '1'
by something_else I mean the name of any other column(s) that you want to be included in the result. So if you have column like 'model_name' then it will be a.model_name
You must use 'as a_id' and as 'b_id' because both tables have the same column name 'id', that' why you need to use alias 'as'
uncle_smith 7 Light Poster
aaahhhrrrrr uncle smith i have heard all about you from Ardav he sais you are a legend and a better programmer, But thats a different story 1/ I get no error messages whatsoever i see what i should see but it just does not do anything?
2/$select = $_POST; ? this is a variable for the submit button
3/Are you sying i should just use $_POST; in my script and not turn them into variables, well at least that is what i think i am doing with them
4/ and the forth i will try cause i think i know what you mean!
If you maned your 'select' group then just $_POST and you will automatically get the value of selected item
You normally dont need the value of the submit button. I mean, the button is just used to submit the form and since there is usually only one submit button in the form, you dont need to extract its value.
And yes, you only need one sql in your script - it will be automatically populated with the value of selected item.
uncle_smith 7 Light Poster
Can anyone please help here I have a form that i wish the user to select a product from a drop down box and then query it in a mysql then i would like to the user to input a number in the next field the press the submit button, then the form should do some simple maths and display it in the next field. now 3 things my code does not do 1/ the math and display it 2/the user input and the product i would like to remain after the form has been submitted 3/ also can anyone give some idea of how to get the form to calculate without a submitt button. here is my code:
<form action="scdc_selfcompletion.php" method="post"> <select name="bap10"> <option selected="selected">Select One</option> <option value="Energy Efficient Cooking">Energy Efficient Cooking</option> <option value="Re-Usable Bags">Re-Usable Bags</option> <option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option> <option value="No Stand By">No Stand By</option> <option value="Use Energy Meter">Use Energy Meter</option> <option value="Use Radio Other Than TV">Use Radio Other Than TV</option> <option value="Recycling">Recycling</option> <option value="Stop Junk Mail">Stop Junk Mail</option> </select> </td> <td width="19%"> <input name="pledging" type="text" id="pledging" maxlength="5" /> </td> <td> </td> <td> </td> </tr> <tr> <td colspan = '3'>Total Savings and Expenditure</td> <td> </td> <td> </td> </tr> </table> <input type="Submit" name="select" value="select"> </form> <?php $select = $_POST['select']; // if something has been chosen if (!empty($select)) { // get the chosen value $bap1 = $_POST['bap1']; $bappledging1 = $_POST['pledging1']; $bap2 = $_POST['bap1']; $bappledging2 = $_POST['pledging1']; $bap3 = $_POST['bap1']; $bappledging3 = $_POST['pledging1']; $bap4 = $_POST['bap1']; $bappledging4 = $_POST['pledging1']; $bap5 = $_POST['bap1']; …
uncle_smith 7 Light Poster
I have this...
<?php $links = explode("\n", $_POST['links']); foreach ($links as $links) { echo '[PART="NUM"]'.$links.'[/PART] <br />'; } ?>
Where it says NUM I want the number of its position in the array.
So if I fed this to this script:
http://www.google.com http://www.yahoo.com http://www.ask.com
The script would then output:
[PART="1"]http://www.google.com[/PART] [PART="2"]http://www.yahoo.com[/PART] [PART="3"]http://www.ask.com[/PART]
How would I go about doing this?
assuming the array is numeric (meaning keys are numeric starting from 0), here is your code:
foreach ($links as $key => $links)
{
echo '[PART="'.$key.'"]'.$links.'[/PART] <br />';
}
enjoy
uncle_smith 7 Light Poster
I have developed a site in PHP 5.26, which is running perfectly from the development server. But after uploading the site to the Web server, it is not working. The server is running PHP 4.4. I haven't used any specific features of PHP 5, so the site should have worked fine in PHP 4.4 also.
I am not getting any errors, but no output either. All I can see is a blank page.
Is there a way to find out if the code is not working due to version incompatibility ?
Another problem I am getting is that some popup windows are opening, but not closing automatically from the
window.close() - javascript statement. If I check the code from the 'View Page Source' option, I can see that the entire <SCRIPT>..</SCRIPT> section is missing. What could be the reason for this ?Thanks
I would start with looking in the error log. and maybe also add this at top of your script
error_reporting(E_ALL);
in php.ini enable the display of error:
display_errors = On;
display_startup_errors = true;
This may help you to spot errors
uncle_smith 7 Light Poster
Can i call a flash function from php?
What exactly do you want to acheive?
If you want to generate flash movie using php, then yes, it's possible
uncle_smith 7 Light Poster
Im so confused on this mod_rewrite..
I am reading all these guides but they all have me confusedRewriteRule ^([A-Za-z0-9-]+)/?$ article.php?name=$1 [L]
Is the first portion(the pattern) checking the second? and then how does it knw what to swap it to?
Uncle's Smiths answer didnt work either and this has gotten me all messed up!
First thing - make sure the rewrites are enabled on your server. If it's not, then you will be just wasting your time.
Second, even if rewrite rules are enabled, make sure they are allowed in .htaccess file. Sometimes you are limited to which directives are allowed in the .htaccess
Best thing to do is to put rewrite rule inside the apache <virtualHost> container in the httpd.conf
Now for your question
if you want your rule to work exactly for a this type of url:
http://www.somesite.com/{dynamic_article_title}.php
then change my first suggestion to this:
RewriteRule ^/([a-zA-Z_\-]+)\.php$ /post.php?a=$1 [L]
uncle_smith 7 Light Poster
So just to clarify, it's not the login process that it is protecting, it's the database side of things i.e. if the cracker was able to get access to the database, right?
Correct. YOu can't protect the login process with any tricks. If a lame user uses password 12345, the its a good change a cracker will guess it eventually, no matter what you do on the server side.
There are, however techniques to protect against password guessing. What you need to do is log the failed login attempts into a temporaty table, along with username, ip address and timestamp and then on every login attempt check that table and if the number of failed attempts > allowed preset limit withing the pre-set time interval, then show an error message that tells user that he must wait 10 minutes before trying again. Your script will then refuse any login attempts for that username, just dont check any more password for 10 minutes
That will help against robots trying to guess password.
Shanti C commented: Good Explanation.... +3
uncle_smith 7 Light Poster
Hey all,
I have been searching and searching no luck yet.
I think what i have come up with is using apaches rewrite map, but clueless as to where to begin.Here is the situation I have.
I have a url
http://www.somesite.com/post.php?id=13and want to turn it into a SEO friendly url like
http://www.somesite.com/{dynamic_article_title}.phpThe title is being pulld from a MySQL table.
Any suggestions as to where I should start or possible examples?
Am I on the right track with Rewrite map?Thanks in advance!
First you need to write your php script in such a way that instead of article id you can pass an article title.
For example instead of post.php?id=13
it should be post.php?id=my_article_title_goes_here
Your php script will then replace underscores with spaces and then pull the article from database using the title instead of article ID.
Once your php script works, you can add a rewrite rule to .htaccess or httpd.conf
RewriteRule ^/([a-zA-Z_\-]+)/\.html$ /post.php?a=$1 [QSA,L]
See this - you can even use the .html extension in your url to make it really look like a static url
uncle_smith 7 Light Poster
Salt has nothing to do with sutiation where cracker can keep guessing passwords.
It will help in case where someone steels your database. You have to realize that md5 is not unhackable. There are many good ways to reverse the md5 hash back to the original value especially when the original value is a common word.
But when the salt has been added before the md5 is applied, then reversing to the original will be impossible.
So to answer your question - yes, good idea, do it. It will protect your database in case someone copies it or steals it any other way.
uncle_smith 7 Light Poster
What is this?
I mean is this like a blogging engine or what?
uncle_smith 7 Light Poster
I used (tried) several wysig editors. Finally I made my choise: YUI RTE
It's very easy to implement, easy to extend (add new features, new buttons), easy to use with Ajax based forms.
It's free, lightweight, you can even include a javascript right from yahoo's server, they allow this.
http://developer.yahoo.com/yui/editor/
Try it, use it, you can thank me later.
uncle_smith 7 Light Poster
This is a very complicated topic and there are many possible solutions, each one would have different requirements.
First of all - is your site database driven? If yes, then do you want to load-balance database server too or just keep one backend database server and several front-end web servers?
The most simple solution is NOT doing this from apache or php, but from DNS server. User round robin dns to resolve the domain to different IP addresses, where different IP address is returned for a DNS query from the list of IP addresses in circles or randomly.
See if your dns server has this feature, if not, then loop for DNS service provider (google DNS server or DNS hosting) that offers this.
uncle_smith 7 Light Poster
I think if you cast to integer, php will automatically do this for you.
$val = '10.000';
$val = (int)$val;
$val should become just 10 now.
You can also try printf or sprintf functions to format your string
and if you want to preserve the decimal points then try
floatval()
for example floatval('10.300') should result in 10.3
uncle_smith 7 Light Poster
hi
I have a for loop that extracts information from news websites and insert them into my database. How do I make the loop stops after it successfully inserts 5 rows?
count the number of inserts, add $numInserts <= 5 in the for loop condition
$numInserts = 0;
for($i = 0; ($i<=$countNews && $numInserts <=5); $i+=1){
// do you stuff, after every insert add
// $numInserts +=1;
}
basically the for loop can have anything in condition part that evaluates to true or false.
If this looks complicated, you can then do this:
$numInserts = 0;
for($i = 0; ($i<=$countNews); $i+=1){
// do you stuff, after every insert add
$numInserts +=1;
if($numInserts === 5){
break;
}
}
The break; will end the loop for you.
uncle_smith 7 Light Poster
Ok so heres the code . The error is this:
$row[title]$row[content]
$row[date]
$row[title]
$row[content]
$row[date]
$row[title]
$row[content]
$row[date]
i mean thats all i get!
and the code is this<html> <head> <link rel=stylesheet type=text/css href=style.css> <title> Blog </title> </head> <body> <?php $username = $_SESSION['username']; include("header.php"); include("dbcon.php"); dbcon(); $result = mysql_query("SELECT * FROM blog WHERE username='$username'") or die(mysql_error()); while ($row = mysql_fetch_array( $result )){ echo "<br>"; echo "<br>"; echo "<center>"; echo "<div class=blog>"; echo "<u><h1>"; echo '$row[title]'; echo "</u></h1>"; echo "<br>"; echo "<br>"; echo '$row[content]'; echo "<br>"; echo "<br>"; echo "<i>"; echo '$row[date]'; echo "</i>"; echo "<br>"; echo "<br>"; echo "</center>"; echo "<div>"; } ?> </body> </html>
Try to use double quotes instead of a single quotes around
$row[whatever], like this:
echo "$row[title]"; instead of echo '$row[title]';
if does not work, then do this (no quotes at all here:):
echo $row[title];
uncle_smith 7 Light Poster
Please help me find errors in this code, because it is not displaying what i requested. PLease answer A.S.A.P
$query = mysql_query("SELECT * FROM member"); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { if(mysql_num_rows($result) == 0) $result = mysql_query("UPDATE member SET flgCurrent = 'false' WHERE idMember =" .$row[0]); echo $row; echo "<br />"; }
what do you want to be displayed?
The line
echo $row;
will not display any useful info because $row is an array, it will just output something like Array
You should at least specify an array key like $row[0]
uncle_smith 7 Light Poster
Thanks khess. Tried your suggestion but just get a blank browser page now.
uncle_smith - the file i am testing with is only 1kb.
I have tried commenting out the headers 1 by 1 but either still get 0kb file or a blank page.In the bin_data field I have "[BLOB - 0 B]". How do I verify that that is binary data? Does "0 B" indicate that the file does not contain data?
Thanks,
TMLAH
0KB means it's probably an empty field
You can try to send contents of that field to the log and look at it.
You can just create an empty file like log.txt, make sure it's writable
then in your script add
file_put_contents($dataT, 'log.txt')
If $dataT is not empty you will see some binary output in the log.txt
if log.txt is still empty, then you now you've got no content in that file
uncle_smith 7 Light Poster
Hello,
I have a script that allows user to upload a file to a mysql 5 database. That is working OK. The File size is accurate. However, my download script is for some reason downloading the files without any content - 0KB. The files are OK when I open them directly. I have tried code with .doc, .pdf, .txt and the same result.Here is my code for viewing the files:
<?php ini_set('display_errors', E_ALL); include "open_db.inc"; $sql = "SELECT * FROM tbl_Files "; $sql .= "ORDER BY filename ASC"; $result = mysql_query($sql, $db); $rows = mysql_num_rows($result); echo "<table>\n"; echo " <tr>\n"; echo " <td>ID</td>\n"; echo " <td>Filename</td>\n"; echo " <td>Type</td>\n"; echo " <td>Size</td>\n"; echo " <td>Description</td>\n"; echo " <td> </td>\n"; echo " </tr>\n"; while ($rows = mysql_fetch_object($result)) { echo " <tr>\n"; echo " <td>$rows->id_files</td>\n"; echo " <td>$rows->filename</td>\n"; echo " <td>$rows->filetype</td>\n"; echo " <td>$rows->filesize</td>\n"; echo " <td>" . stripslashes($rows->description) . "</td>\n"; echo " <td>( <a href='download.php?id_files=$rows->id_files'>Download</a> )</td>\n"; echo " </tr>\n"; } mysql_free_result($result); mysql_close($db); ?>
The code for download.php is:
<?php ini_set('display_errors', E_ALL); if (isset($_GET['id_files'])) { $id_files = $_GET['id_files']; include "open_db.inc"; $sql = "SELECT id_files, bin_data, filetype, filename, filesize FROM tbl_Files WHERE id_files=$id_files"; $result = @mysql_query($sql, $db); $dataT = @mysql_result($result, 0, "bin_data"); $name = @mysql_result($result, 0, "filename"); $size = @mysql_result($result, 0, "filesize"); $type = @mysql_result($result, 0, "filetype"); header("Content-type: $type"); header("Content-length: $size"); header("Content-Disposition: attachment; filename=$name"); header("Content-Description: PHP Generated Data"); header("Content-transfer-encoding: binary"); echo $dataT; } else { echo 'id_files not set'; } ?>
I would appreciate any help.
Thanks,
TMLAH
Have you verified that content …
uncle_smith 7 Light Poster
$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error()); $tip = $details['TotalHouseholds']; $perc = 21.33% $sumone= $tip*$perc;
could anyone tell me if this is remotley correct i have tryed it in a browser but i get the page displayed normally with a nice line of code telling me am bit confused the code is supposed to pull some data from a mysql database and multiply it by 21.33% you would proberlt think it is simple but i am newand i want to cry!!!!
No, this is not remotely correct.
What you declare $perc = 21.33% the php sees it as saying divide 21.33 by undefined, so it tries to divide by 0 and gets this error.
Hint: the % has a special meaning in php to calculate the remainder of a division operation. It's called Modulus
Also where does the $details come from? You have not declared any value for $details.
Anyway, if you want to calculate 21.33 percent of 200 for example, you just have to divide 200 by 100 and multiple by 21.33 like this:
200 / 100 * 21.33
You can then add a percentage sign if you want it to be displayed in result.
uncle_smith 7 Light Poster
I have a simple problem and I do not want to write 24 if statements.
I am creating a URL string which requires precise formatting to work. This URL is getting created on the fly based on variables ($Layer1.','.$Layer2.','.$Layer3)
I pass in to create the URL string. The URL string requires a format like this:
http://test/map.php5?LAYERS=Layer1,Layer2,Layer3&QUERY_LAYERS=Layer1,Layer2,Layer3
The problem lies when I only pass lets say two of the variables. My URL now looks like:
http://test/map.php5?LAYERS=,Layer2,Layer3&QUERY_LAYERS=,Layer2,Layer3
The application accepting this URL is certainly not happing with a leading comma.
FYI - Variables declared as follows:
$Layer1="Layer1";
$Layer2="Layer2";
$Layer3="Layer3";Any idea how I can get this to work without testing every possible combination?
Thanks in advance,
Mapper
Solution: pass your variables as an array, then use implode(',' $arr);
the implode function will automatically join the array pieces into a string separated by ',' and will not add the leading comma
http://us3.php.net/implode
Another solution is do whatevery you are doing now, then use ltrim($url, ',');
This will remove the leading ',' from the string - ltrim means trim the left side of string, you pass the string itself and second argument is collection of chars you want to trim, in your case its a comma
uncle_smith 7 Light Poster
Hi Please any one help me with a secure php image upload script... With out change the destination folder's chmod to 0777..... Please help me....... I am using php apache server...
thx in advance
0777 is never necessary for upload scripts. 0666 is enough.
an even better permission or 0660 but then make sure that the directory is owned by the same group or the same user that apache runs under.
uncle_smith 7 Light Poster
The code is this:
<html>
<head>
<link rel=stylesheet type=text/css href=style.css>
<title>
Search Results
</title>
</head>
<body>
<?php include("header.php"); ?>
<center>
<div class=indexboxlarge2>
<?php
SESSION_start();
include("dbcon.php");
$searchresult = $_POST['result'];
dbcon();
$query = mysql_query("SELECT * FROM user_info WHERE 1_name LIKE '%$searchresult%' OR WHERE 2_name LIKE '%$searchresult%'") or die(mysql_error());
$total = mysql_num_array($query);
if ($total!=0) {
while ($row = mysql_fetch_array($query)) {
echo $row["1_name"];
echo " ";
echo $row["2_name"];
echo "<br>";
echo "<br>";
}
}
else
{
echo "Sorry there results to display.";
}
?>
</div>
</center>
</body>
</html>
i get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 2_name LIKE '%"the search result%'' at line 1
Were i wrote the search result is what the user input is.
Any help will be happily accepted,
jakx12
You not supposed to have 2 'WHERE'
try this:
WHERE 1_name LIKE '%{$searchresult}%' OR 2_name LIKE '%{$searchresult}%'
and you may want to try to use backticks (key above the tab key) to quote the field names like this:1_name