Is there an easy way (preferably with htaccess and mod_rewrite) to force the browser to always access a site with the www. prefix (adding it automatically where necessary?)
Thx.
Hi all,
I've got a, I think fairly easy question, but this is bugging me for a while now. So I figured, maybe I can get some help here.
Since recursive functions are always a bit tricky, and sometimes a bit unclear to me, I keep struggling to create a nice working solution to get my menudata.
In one of my classes I have this function, which gives me all menu-items recursivly. The thing I want is to determine at which recursionlevel a certain object was retrieved so I can create a nicely looking HTML output with indents for the levels of nesting.
public function GetObjectList($parentID = 0, $objectlist = null)
{
if(is_null($objectlist))
{
$objectlist = new ObjectList("Model_Navigation");
}
$query = MySQL::Query("SELECT * FROM `Navigation` WHERE `WebsiteID` = ".SITE_ID. " AND `LanguageID` = ".LANG_ID." AND `ParentID` = ".$parentID);
while($result = MySQL::FetchAssoc($query))
{
$object = new Model_Navigation();
$object->ID = $result["ID"];
$object->WebsiteID = $result["WebsiteID"];
$object->LanguageID = $result["LanguageID"];
$object->ParentID = $result["ParentID"];
$object->Name = $result["Name"];
$object->Page = Model_Page::GetObjectByID($result["PageID"]);
$object->ExternalURL = $result["ExternalURL"];
$object->Index = $result["Index"];
$object->Level = [here lies my problem];
$objectlist->Add($object);
self::GetObjectList($object->ID, $objectlist);
}
return $objectlist;
}
Hope to hear from you!
Greetings from Holland,
Ben Fransen
$_SERVER['REMOTE_USER'] returns the username of the user logged in to an Active Directory. I want to retrive this users info by using ldap_search().
This is what I have now:
$ad = // ldap_connection id
$filter = "(|(sn=$username*)(givenname=$username*))";
$attr = array("displayname", "mail", "mobile", "homephone", "telephonenumber", "streetaddress", "postalcode", "physicaldeliveryofficename", "l");
$dn = // OU, DC etc..
ldap_search($ad,$dn,$filter,$attr);
It works, but i'm not sure it will work if two users have almost the same names.
How do I only search for their unique username so that i always only get one user?
I need a way to convert a number into formatted way by inserting comma at suitable places. Can it be done using regex?
Example:
12345 => 12,345
1234567 =>1,234,567
SO I am trying to create a way to structure my database to be able customize forms.
I looked into EAV pattern and here is my db structure:
Table form
- form_id
- form_name
- form_added_on
- form_modified_at
Table: form_fields
- field_id
- form_id
- field_type (TEXT, RADIO etc..)
- field_default_value
- field_required
Table: form_data
- data_id
- field_id
- form_id
- field_value
so now I can store any custom form into the database and if I want to get the values for an individual form I can simply join it by "form_id" ..
the problem:
I want to be able to search through all the forms for a specific field value.
How can I do that with EAV model?
Also, I thought about just storing the custom data as a serialized (JSON) object but then I am not sure how can I query that data.
Please note that I am using Codeigniter with MYSQL. So if conversation can use Codeigniter libraries if needed.
so I have lots of users posting articles with names in different languages. I need some lib to translate thouse article names to english letters for example turn russian '?' into eng 'r' and so on for all european languages, russian and asian languages. Where to get such lib?
Im using the Zend Lucene however Im have a little trouble. I wish to query the index for the exact tring so page_name IS test123, not any fuzzy match.
Currently I have:
$hits = $index-find('page_name:"test123"');
And advice appreciated, thanks!
I'm not using an off-the-shelf framework and don't particularly want to (nor d I want to go into the reasons why...). Anyway, onto my question(s), I hope it make sense....
I'm trying to get my head around what should go in the model and what should go in the controller. Originally I had the impression that a model class should represent an actual object (eg - a car from the cars table of a database) and model properties should mirror the database fields. However I'm now getting the feeling that I've got the wrong idea - should an instance of a model class represent an actual item, or should it contain a number of methods for doing stuff - sometimes to one car or sometimes to multiple cars based on my example earlier.
For example I want to get all the cars from a the database and show them in the view. Am I right in think it should be along the lines of this?
Controller File
function list() {
$cars = $this->model->get_all();
$this->view->add($cars);
$this->view->render('cars-list');
}
Model File
function get_all() {
// Use a database interaction class that I've written
$cars = Database::select();
return $cars;
}
Now, if the car had a "status" field that was stored as an integer in the database and I wanted to change that to a string, where should that be done? By looping the SQL results array in the get_all() method in the model?
Also, where should form validation live? I have written a validation class that works a little like this:
$validator = new Validator();
$validator->check('field_name', 'required');
If the check fails, it adds an error message to the array in the Validator. This array of error messages would then get passed to the view. Should the use of my validator class go in model or the controller?
Thanks in advance for for any help anyone can offer. If you know of any links to a simple MVC example / open source application that deals with basic CRUD, they would be much appreciated.
Hello, can't understand mysql error:
UPDATE static_pages SET order = " Some
new data 222222
"Database 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 'order = "
$query = 'UPDATE someTable SET '.$key.' = "'.$value.'"';
Here is $key = order; $value = 'new data 222222';
There is such keys in table: order, prices, contacts. Each of these updates well except the 'order'. Why?
array(
[0]
name => 'joe'
size => 'large'
[1]
name => 'bill'
size => 'small'
)
I think i'm being thick, but to get the attributes of an array element if I know the value of one of the keys, I'm first looping through the elements to find the right one.
foreach($array as $item){
if ($item['name'] == 'joe'){
#operations on $item
}
}
I'm aware that this is probably very poor, but I am fairly new and am looking for a way to access this element directly by value. Or do I need the key?
Thanks,
Brandon
Is mysql_real_escape_string sufficient for cleaning user input in most situations?
::EDIT::
I'm thinking mostly in terms of preventing SQL injection but I ultimately want to know if I can trust user data after I apply mysql_real_escape_string or if I should take extra measures to clean the data before I pass it around the application and databases.
I see where cleaning for HTML chars is important but I wouldn't consider it necessary for trusting user input.
T
My application requires the user to enter their business name, which the application will automatically create into a unique identifier to be used in URLs, ie
"Bob's Cafe" will become "bobs-cafe"
But if there are duplicate names I would like the application to add a number so if there is already a "bobs-cafe" we will use "bobs-cafe-1" and likewise if there is already a "bobs-cafe-1" we will use "bobs-cafe-2"
Ive used explode and also looked at a regular expressions but I dont know the best way to approach this.
Im stuck in being able to grab the number and incrementing it and returning the string
i need some code which can delete/filter arrays which doesn't contain a specific word
or we can say keep only that contain a specific word and drop all other ones
I have a select menu that displays countries. It looks at the DB and judging by the value in the db shows the option as selected. Is there a simpler way off doing this than:
if ($country == 'AG') {echo '<option value="AG" selected="selected">Antigua</option>';}
else {echo '<option value="AG">Antigua</option>';};
if ($country == 'AR') {echo '<option value="AR" selected="selected">Argentina</option>';}
else {echo '<option value="AR">Argentina</option>';};
if ($country == 'AM') {echo '<option value="AM" selected="selected">Armenia</option>';}
else {echo '<option value="AM">Armenia</option>';};
if ($country == 'AW') {echo '<option value="AW" selected="selected">Aruba</option>';}
else {echo '<option value="AW">Aruba</option>';};
if ($country == 'AU') {echo '<option value="AU" selected="selected">Australia</option>';}
else {echo '<option value="AU">Australia</option >';};
if ($country == 'AT') {echo '<option value="AT" selected="selected">Austria</option>';}
else {echo '<option value="AT">Austria</option>';};
if ($country == 'AZ') {echo '<option value="AZ" selected="selected">Azerbaijan</option>';}
else {echo '<option value="AZ">Azerbaijan</option>';};
if ($country == 'BS') {echo '<option value="BS" selected="selected">Bahamas</option>';}
else {echo '<option value="BS">Bahamas</option>';};
if ($country == 'BH') {echo '<option value="BH" selected="selected">Bahrain</option>';}
else {echo '<option value="BH">Bahrain</option>';};
There are a lot of countries and doing this would be madness wouldn't it????
Here I have a variable 'response' which is obtained by parsing an XML file.
$url = 'http://xxxxx.xml';
$ch = curl_init($url);
$response = curl_exec($ch);
The url structure is as follows -
<user>
<id>734</id>
<name>Peter Parker</name>
-
<status>
<favorited>false</favorited>
</status>
</user>
How to access each bit of info like id,name,favorited from response?
I need to get a total count of JPG files within a specified directory, including ALL it's subdirectories. No sub-sub directories.
Structure looks like this :
dir1/
2 files
subdir 1/
8 files
total dir1 = 10 files
dir2/
5 files
subdir 1/
2 files
subdir 2/
8 files
total dir2 = 15 files
I have this function, which doesn't work fine as it only counts files in the last subdirectory, and total is 2x more than the actual amount of files. (will output 80 if I have 40 files in the last subdir)
public function count_files($path) {
global $file_count;
$file_count = 0;
$dir = opendir($path);
if (!$dir) return -1;
while ($file = readdir($dir)) :
if ($file == '.' || $file == '..') continue;
if (is_dir($path . $file)) :
$file_count += $this->count_files($path . "/" . $file);
else :
$file_count++;
endif;
endwhile;
closedir($dir);
return $file_count;
}
Is it necessary to validate a name or street address? when I have it coded in the following format. And if so why?
$address = mysqli_real_escape_string($mysqli, htmlentities($_POST['address']));
$name = mysqli_real_escape_string($mysqli, htmlentities($_POST['name']));
Hello,
I am using this IP Validation Function that i came across while browsing, it has been working well until today i ran into a problem.
For some reason the function won't validate this IP as valid: 203.81.192.26
I'm not too great with regular expressions, so would appreciate any help on what could be wrong.
If you have another function, i would appreciate if you could post that for me.
|--------------------------------------------|
The code for the function is below:
|--------------------------------------------|
public static function validateIpAddress($ip_addr)
{
global $errors;
$preg = '#^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}' .
'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#';
if(preg_match($preg, $ip_addr))
{
//now all the intger values are separated
$parts = explode(".", $ip_addr);
//now we need to check each part can range from 0-255
foreach($parts as $ip_parts)
{
if(intval($ip_parts) > 255 || intval($ip_parts) < 0)
{
$errors[] = "ip address is not valid.";
return false;
}
return true;
}
return true;
} else {
$errors[] = "please double check the ip address.";
return false;
}
}
Hi guys...
Hope this isn't a waste of your time. I'm working on a project, and it occured to me that there's a chunk of code out there, that should allow me to see how others have implemented this.
I've got a project where I'm going to have a page, with a sel box. the user will select an item from the selList, and based on the item selected, a separate section of the page (areaB) will change in terms of the content/tbls being displayed.
i then want to allow the user to go through a series of subpages in areaB, where the user goes through a submit/cancel/confirm process, where the stuff in areaB changes, with the rest of the page remaining the same...
i'm trying to figure out the best approach to implement the on both client/server side.
i could just have an ugly "if block" where i have abunch of logic, and i completely regen the page each time the user selects an action..
i could have an approach that might involve divs/frames, where i then just regen the targeted frame/div area.. is this even possible??
i could have some form of ajaxy process, which would only alter the targeted section(s) of the page...
so.. i'm trying to talk to anyone who has ideas on how to do this, or more ideally, if you know of a good code (client/server) side example of this... that i can examine. i'd really appreciate it!!
i've got a more detailed overview but didn't know if it would be cool to post it here...
thanks..
tom
This article states that
If your site is run on a shared Web
server, be aware that any session
variables can easily be viewed by any
other users on the same server.
On a larger host like GoDaddy, are there really no protections in place against this? Could it really be that easy? If it is that easy, where are the session vars of the other users on my host so I can check them out?
Edit: I didn't believe it, but here's my little program which shows that this is true! I wonder if those are really the same as the value stored in the cookies on the users' machine?
MySQL
$selectSize = "SELECT * FROM products";
$querySize = $db->select($selectSize);
while ($product = $db->fetcharray($querySize)) {
HTML
<ul>
<li>Product A</li>
<li>Product B</li>
<li class='right'>Product C</li>
<li>Product D</li>
<li>Product E</li>
<li class='right'>Product F</li>
</ul>
Question
While getting the product, I want the Product C and Product F or any product after 3 loops will have class='right' to the list style. Let me know
Thanks
Hi guys,
I've got this code
mysqli_query ( $userdatabase,
'CREATE TABLE `user_'.$emailreg.'` (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
IP varchar(10),
FLD1 varchar(20),
FLD2 varchar(40),
FLD3 varchar(25),
FLD4 varchar(25),
FLD5 varchar(25) )' );
echo ( mysqli_error ($userdatabase) );
that works fine on my localhost, but when I upload it to the server, it starts giving me a "Incorrect table name '[email protected]'" error. any idea?
Thanks!
I hate that google can not search for symbols. I saw this in some sample code and wondered why there is an @ sign before the readfile function:
@readfile($filename);
What does it mean different to without an @ symbol?