Web Development Questions That Don't Need Their Own Thread v2
3,079 replies, posted
Ohh, I think I see now; in the first var declaration, you have a semicolon at the end of the first line, so the var casting isn't applied to the other two variables declared (including result/success). Try fixing that to see if that helps anything; without the var, the scoping gets confusing.
Sorry if this isn't descriptive enough, if I were on the computer, I would copy the block I'm referencing.
[QUOTE=deadeye536;32266765]Ohh, I think I see now; in the first var declaration, you have a semicolon at the end of the first line, so the var casting isn't applied to the other two variables declared (including result/success). Try fixing that to see if that helps anything; without the var, the scoping gets confusing.
Sorry if this isn't descriptive enough, if I were on the computer, I would copy the block I'm referencing.[/QUOTE]
Thanks for pointing that out! Sadly it's still returning False.
[php]function getLocation(address)
{
var location = (address) ? address : $('#location-input').val(),
locationChanged = (address && lastLocation != location) ? true : locationChanged,
success = false;
var request = {
origin: location,
destination: '52.697605, -2.021616',
travelMode: g.DirectionsTravelMode.DRIVING
};
if (locationChanged && lastLocation != location)
{
$('#spinner').fadeIn(200);
directions.route(request, function(response, status)
{
if (status == 'OK')
{
var route = response.routes[0];
addressName = route.legs[0].start_address,
lastLocation = (address) ? location : addressName;
$('#location-input').removeClass('error').val(addressName);
map.setMapTypeId(g.MapTypeId.ROADMAP);
directionsDisplay.setDirections(response);
locationChanged = false;
success = true;
}
else if (status == 'OVER_QUERY_LIMIT') { alert('The server could not be reached, please try again later!'); }
else { $('#location-input').addClass('error'); }
$('#spinner').fadeOut();
});
}
console.log(success);
return success;
}[/php]
Changed code.
Is there a list/sql table of all the areas/locations in New York?
[QUOTE=Giraffen93;32268297]Is there a list/sql table of all the areas/locations in New York?[/QUOTE]
[url]http://www.geonames.org/[/url]
This could be useful. It's used on Steam as well.
[QUOTE=Murkrow;32269034][url]http://www.geonames.org/[/url]
This could be useful. It's used on Steam as well.[/QUOTE]
yeah but i need it like more of a table:
id - areaname - parentlocation
type of thing, that seems kinda complicated..
[QUOTE=NorthernGate;32254659]Any of you guys have any experience or tips on converting a custom website to a drupal theme? I despise drupal with most of the fibers in my being, but the company is insisting on using drupal for now. So I have to convert all the work I've done thus far into a drupal theme. Bleh. And drupal isn't cooperating as well as I might have hoped.[/QUOTE]
Heh, it's actually my favourite CMS.
Drupal 6 or 7?
Generally I just modify the default page.tpl.php ([url]http://api.drupal.org/api/drupal/modules--system--page.tpl.php/7/source[/url]), stripping out all of the HTML used for layout, and then write my theme around each output function.
If you aren't as familiar with Drupal, it might be easier to develop a static HTML/CSS page then replace the different page sections (footer, sidebar, navbar etc) one by one with Drupal output (regions and variables).
Let me know if you have any specific questions.
[QUOTE=jaybuz;32266186]I don't understand this:
[img]http://dl.dropbox.com/u/386727/Web-And-Graphics/webkit-breakpoint.png[/img][/QUOTE]
[QUOTE=Ac!dL3ak;32247335]OOOH i know
pick me
when you define the callback function for directions.route, it will not be run in the same (scope, i guess?) as where you defined route as false before. Since that route never changes, it will always turn false and the object route off of window might have the actual route information
just a thought[/QUOTE]
How are my skills? (Sample code)
[php]
function login($username = false, $password = false) {
global $dbh, $loginErrors;
$dbPassword = NULL;
$sql = "SELECT id, username, password FROM accounts WHERE username = :username";
try {
$query = $dbh->prepare($sql);
$query->bindParam(':username', $username, PDO::PARAM_STR, 24);
$query->execute();
$numRows = $query->rowCount(); // getting number of rows returned
} catch (PDOException $e) {
//echo $e->getMessage(); need some way of logging this error, db maybe?
echo 'PDO error in f.login 1!'; // temporary till I figure something out
}
//echo $numRows . '<br />' . $username;
if ($numRows == 1) { // if user exists. could also just do if($numRows){}
try {
$fetch = $query->fetch(PDO::FETCH_ASSOC);
$dbId = $fetch['id'];
$dbUsername = $fetch['username'];
$dbPassword = $fetch['password']; // assigning dbPassword from assoc array
if (enc($password) == $dbPassword) { // if entered password matches db password
setCookies($dbId, $dbUsername, $dbPassword);
header("Location: index");
} else {
$loginErrors[] = 'Password did not match';
}
} catch (PDOException $e) {
//echo $e->getMessage();
echo 'PDO error in f.login 2!';
}
} else {
$loginErrors[] = 'Username was not found';
}
}
[/php]
[php]
function verifyLoggedIn() { // check if user is logged in
global $dbh;
if (isset($_COOKIE['username']) AND isset($_COOKIE['password'])) {
$username = Secure::clean($_COOKIE['username']);
$password = Secure::clean($_COOKIE['password']);
$sql = "SELECT username, password FROM accounts WHERE username = :username";
try {
$query = $dbh->prepare($sql);
$query->bindParam(':username', $username, PDO::PARAM_STR, 24);
$query->execute();
$fetch = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
//echo $e->getMessage();
echo 'PDO error in verify function!';
}
$numRows = $query->rowCount();
if ($numRows == 1) { // if found username
if ($password == $fetch['password']) { // now check if cookie password is matched with db password
return TRUE;
} else {
return FALSE; // cookie password didn't match with db password
}
} else {
return FALSE; // didn't find username
}
} else {
return FALSE; // cookies aren't set
}
}
[/php]
[php]
function enc($string) {
global $config;
$hash = md5("$config[salt] $string");
return $hash;
}
[/php]
[php]
// in a global file:
if (verifyLoggedIn()) {
$getInfo = new GetUserInfo($_COOKIE['username']); // remember, verifyLoggedIn makes sure the username is valid
}
[/php]
[php]
// made this class myself, without any help, pretty proud of it
class GetUserInfo {
public $uid, $username, $password, $email, $rank, $location, $age, $gender, $regDate, $lastLogin;
public function __construct($username) {
global $dbh;
$sql = "SELECT * FROM accounts WHERE username = :username";
try {
$query = $dbh->prepare($sql);
$query->bindParam(':username', $username, PDO::PARAM_STR, 24);
$query->execute();
$fetch = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "PDO error in getUserInfo";
}
$this->uid = $fetch['id'];
$this->username = $fetch['username'];
$this->password = $fetch['password'];
$this->email = $fetch['email'];
$this->rank = $fetch['rank'];
$this->location = $fetch['location'];
$this->age = $fetch['age'];
$this->gender = $fetch['gender'];
$this->regDate = $fetch['reg_date'];
$this->lastLogin = $fetch['last_login'];
}
}
[/php]
Just some little snippets. I wanted to try my traditional style of a login script except this time using PDO. This code isn't made for a huge public website, I know. And the verifyLoggedIn function could do with more advanced techniques.
I've been learning php on/off for the past month starting with only basic c++ knowledge.
One last thing: I kind of want to build website back-ends as a side job. It's fun and makes me think. But what would you guys recommend I learn next to be able to do this for people? Think I am lacking in the advanced concepts department.
[QUOTE=Lequinx;32278630][php=2,33,40]
function login($username = false, $password = false) {
global $dbh, $loginErrors;
$dbPassword = NULL;
$sql = "SELECT id, username, password FROM accounts WHERE username = :username";
try {
$query = $dbh->prepare($sql);
$query->bindParam(':username', $username, PDO::PARAM_STR, 24);
$query->execute();
$numRows = $query->rowCount(); // getting number of rows returned
} catch (PDOException $e) {
//echo $e->getMessage(); need some way of logging this error, db maybe?
echo 'PDO error in f.login 1!'; // temporary till I figure something out
}
//echo $numRows . '<br />' . $username;
if ($numRows == 1) { // if user exists. could also just do if($numRows){}
try {
$fetch = $query->fetch(PDO::FETCH_ASSOC);
$dbId = $fetch['id'];
$dbUsername = $fetch['username'];
$dbPassword = $fetch['password']; // assigning dbPassword from assoc array
if (enc($password) == $dbPassword) { // if entered password matches db password
setCookies($dbId, $dbUsername, $dbPassword);
header("Location: index");
} else {
$loginErrors[] = 'Password did not match';
}
} catch (PDOException $e) {
//echo $e->getMessage();
echo 'PDO error in f.login 2!';
}
} else {
$loginErrors[] = 'Username was not found';
}
}
[/php]
[/quote]
[b]FUCK GLOBALS[/b], return that shit ffs
[quote]
[php=22]
function verifyLoggedIn() { // check if user is logged in
global $dbh;
if (isset($_COOKIE['username']) AND isset($_COOKIE['password'])) {
$username = Secure::clean($_COOKIE['username']);
$password = Secure::clean($_COOKIE['password']);
$sql = "SELECT username, password FROM accounts WHERE username = :username";
try {
$query = $dbh->prepare($sql);
$query->bindParam(':username', $username, PDO::PARAM_STR, 24);
$query->execute();
$fetch = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
//echo $e->getMessage();
echo 'PDO error in verify function!';
}
$numRows = $query->rowCount();
if ($numRows == 1) { // if found username
if ($password == $fetch['password']) { // now check if cookie password is matched with db password
return TRUE;
} else {
return FALSE; // cookie password didn't match with db password
}
} else {
return FALSE; // didn't find username
}
} else {
return FALSE; // cookies aren't set
}
}
[/php][/quote]
Line 22 is going to cause a fatal error if a PDO exception is thrown, as $query won't be defined and you're trying to access a function. Also, why are you not handling the exception properly? Please get an exception handler or just stop execution, continuing on is bad.
[quote]
[php=4]
function enc($string) {
global $config;
$hash = md5("$config[salt] $string");
return $hash;
}
[/php][/quote]
Nonononono
[php]$hash = md5("{$config['salt']} $string");[/php]
Or how about
[php]$hash = md5($config['salt'] . $string);[/php]
Why even set a variable
[php]return md5($config['salt'] . $string);[/php]
[quote]
[php]
// made this class myself, without any help, pretty proud of it
class GetUserInfo {
// ...
}
[/php][/QUOTE]
The GetUserInfo class sounds like it should be called UserInfo tbh.
[QUOTE=sentrix;32278909][b]FUCK GLOBALS[/b], return that shit ffs
Line 22 is going to cause a fatal error if a PDO exception is thrown, as $query won't be defined and you're trying to access a function. Also, why are you not handling the exception properly? Please get an exception handler or just stop execution, continuing on is bad.
Nonononono
[php]$hash = md5("{$config['salt']} $string");[/php]
Or how about
[php]$hash = md5($config['salt'] . $string);[/php]
Why even set a variable
[php]return md5($config['salt'] . $string);[/php]
The GetUserInfo class sounds like it should be called UserInfo tbh.[/QUOTE]
how do you highlight a line of the code
[QUOTE=Ac!dL3ak;32278946]how do you highlight a line of the code[/QUOTE]
do [ php = 2,1,4,5,1,61,35 ] Code here [ / php ]
ie
[php=1,3,4]
1
2
3
4
[/php]
[php=3,5]<?php
echo "hello world";
echo "this is cool";
?>[/php]
oh ya, is there a difference between <?php and <?
[QUOTE=zzlawlzz;32279110]oh ya, is there a difference between <?php and <?[/QUOTE]
nothing except server settings
some servers are set to not read short tags ("<?").
[QUOTE=Ac!dL3ak;32279126]nothing except server settings
some servers are set to not read short tags ("<?").[/QUOTE]
oh ok, for some pages that i made got an error when i had <?php and when i deleted the php and refreshed there was no error :pwn:. maybe i didnt refresh properly.
[QUOTE=zzlawlzz;32279110]oh ya, is there a difference between <?php and <?[/QUOTE]
One you use when you want to start writing PHP code.
The other you never use unless you want to die a slow painful death.
[QUOTE=sentrix;32279249]One you use when you want to start writing PHP code.
The other you never use unless you want to die a slow painful death.[/QUOTE]
and why is that?
So hey uh
Im 110% sure that the code for this site isn't good. Right?
[url]http://ccjshs.putnamschools.org/CCJSHS/CCJSHS_Home.html[/url]
Well it actually has a doctype and uses divs properly (although the absolute positioning on everything is a bit weird). The design's not good, but it's good for a school site I guess.
[QUOTE=sentrix;32279249]One you use when you want to start writing PHP code.
The other you never use unless you want to die a slow painful death.[/QUOTE]
I don't see a problem in updating your php's ini file:
[code]short_open_tag = on
[/code]
Why do people think that short tags are bad, maybe because some people can't edit their php ini? If that is the case then it's clear you are using a shared webhost which is a greater cause of a slow and painful death.
[QUOTE=hacksore;32280410]I don't see a problem in updating your php's ini file:
[code]short_open_tag = on
[/code]
Why do people think that short tags are bad, maybe because some people can't edit their php ini? If that is the case then it's clear you are using a shared webhost which is a greater cause of a slow and painful death.[/QUOTE]
some people just can't afford a VPS
[QUOTE=Ac!dL3ak;32280437]some people just can't afford a VPS[/QUOTE]
[url=https://client.fanaticalvps.com/cart.php?a=add&pid=10]Fanatical have VPS' at $5 a month.[/url] It's really not that much compared to how much value is gained. If you don't want to manage a server and want to be a web developer then I doubt you'll get far, you need to at least know how to manage and setup a web server.
[editline]a[/editline]
Out of Stock :v:
[QUOTE=Jelly;32280610][url=https://client.fanaticalvps.com/cart.php?a=add&pid=10]Fanatical have VPS' at $5 a month.[/url] It's really not that much compared to how much value is gained. If you don't want to manage a server and want to be a web developer then I doubt you'll get far, you need to at least know how to manage and setup a web server.
[editline]a[/editline]
Out of Stock :v:[/QUOTE]
I have one of those actually, just barely enough memory to run nginx and php
[QUOTE=Ac!dL3ak;32280746]I have one of those actually, just barely enough memory to run nginx and php[/QUOTE]
Then you're setting it up wrong, I only use 50MB of RAM with an Nginx and PHP install. 256MB of RAM is plenty.
[QUOTE=hacksore;32280410]...
Why do people think that short tags are bad
...[/QUOTE]
Mainly because they conflict with XML processing instructions, if the server has short tags enabled you have to write out the XML PIs via echo instead of just using them normally.
Edit: Also, short tags are a configuration option, while normal tags will always be supported. So not using them helps portability.
[QUOTE=Jelly;32280767]Then you're setting it up wrong, I only use 50MB of RAM with an Nginx and PHP install. 256MB of RAM is plenty.[/QUOTE]
huh
[QUOTE=Ac!dL3ak;32280746]I have one of those actually, just barely enough memory to run nginx and php[/QUOTE]
im running lighttpd php mysql on 128 easily
[QUOTE=Giraffen93;32268297]Is there a list/sql table of all the areas/locations in New York?[/QUOTE]
This is for a client by the way, if someone makes a database of it you can get paid a little.
Lithiumhosting has it enabled :eng101: (shared hosting)
just saying.
I have shared hosting and I've got access to my php.ini and I can SSH. Pretty sweet if you ask me.
Sorry, you need to Log In to post a reply to this thread.