Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=smidge146;45598597]all good now, resinstalled the server with plesk, this ensure all permissions are set correctly.
[editline]5th August 2014[/editline]
is it possible to have a website where a user can click a button which will run another php script which has a header to return to the original page, but if the user was to manually navigate to this script, it wouldn't let them run it without going to the original page and click the button?[/QUOTE]
It's quite simple really. On the first webpage you require a button inside a form, such as this (Extremely minimalistic):
[code]
<html>
<body>
<form action="backend.php" method="POST">
<input type="submit" name="button" value="Click me">
</form>
</body>
</html>
[/code]
And on the php page, just check if there were any POST values.
[code]
<?php
if(count($_POST) != 0)
{
// do something
header("Location: frontend.html");
}
else
{
// User, why don't you press the button instead?
echo "You weren't supposed to come here.";
}
?>
[/code]
[QUOTE=smidge146;45598597]
is it possible to have a website where a user can click a button which will run another php script which has a header to return to the original page, but if the user was to manually navigate to this script, it wouldn't let them run it without going to the original page and click the button?[/QUOTE]
Another way to do it apart from what eternalflamez posted is:
HTML (stolen from eternalflamez because I am lazy :v:)
[code]
<html>
<body>
<form action="backend.php" method="POST">
<input type="submit" name="button" value="Click me">
</form>
</body>
</html>
[/code]
PHP:
[code]
<?php
if (isset($_POST["button"])) {
// Do this if the button was pressed
} else {
// Do this if the person tries to access the script without pressing the button
header("location: foo/bar.php");
exit(); /* Use exit(); or die(); under a header because PHP docs says so :V */
}
[/code]
Hey so I'm trying to make a mock credit card processing system, and I'm realizing that I have no idea how to make SQL queries that use the "and if" functions. Basically right now I'm trying to make it so that the credit card numbers and CVV numbers are processed at the same time, to see if they match up with dummy info I have in a database.
The part I'm having issues with:
[CODE]if (!empty($post_data['ecom_payment_card_number'])) {
$result = mysqli_query($con,"SELECT * FROM ccinfo WHERE ecom_payment_card_number = $ecom_payment_card_number");
$row = $result->fetch_assoc();
echo $row['ecom_payment_card_number'];
}
if($ecom_payment_card_number === $row['ecom_payment_card_number']) {
echo("\r\rFound!");
} else {
echo("Credit card number not found in system. Please re-enter number.");
}
if (!empty($post_data['ecom_payment_card_verification'])) {
$result = mysqli_query($con,"SELECT * FROM ccinfo WHERE ecom_payment_card_verification = $ecom_payment_card_verification");
$row = $result->fetch_assoc();
echo $row['ecom_payment_card_verification'];
if($ecom_payment_card_verification === $row['ecom_payment_card_verification']){
echo("CCV matches!");
} else {
echo("Credit card verification number does not match number associated with card. Please re-enter number.");
}
}[/CODE]
They work separately, but I think I'm too stupid to figure out how to make them work in harmony.
$result = mysqli_query($con,"SELECT * FROM ccinfo WHERE ecom_payment_card_verification = $ecom_payment_card_verification AND ecom_payment_card_number = $ecom_payment_card_number");
It's an AND statement in mysql. "If" is implicit in its and.
More info:
[url]http://dev.mysql.com/doc/refman/5.0/en/where-optimizations.html[/url]
[QUOTE=01271;45604454]$result = mysqli_query($con,"SELECT * FROM ccinfo WHERE ecom_payment_card_verification = $ecom_payment_card_verification AND ecom_payment_card_number = $ecom_payment_card_number");
It's an AND statement in mysql. "If" is implicit in its and.
More info:
[url]http://dev.mysql.com/doc/refman/5.0/en/where-optimizations.html[/url][/QUOTE]
So is this correct?
[code]if (!empty($post_data['ecom_payment_card_number'])) {
$result = mysqli_query($con,"SELECT * FROM ccinfo WHERE ecom_payment_card_number = $ecom_payment_card_number AND ecom_payment_card_verification ===
$ecom_payment_card_verification");
$row = $result->fetch_assoc();
echo $row['ecom_payment_card_number'];
}
if($ecom_payment_card_number === $row['ecom_payment_card_number']) {
echo("\r\rFound!");
}
else {
echo("Credit card number not found in system. Please re-enter number.");
}
if($ecom_payment_card_verification === $row['ecom_payment_card_verification']){
echo("CCV matches!");
} else {
echo("Credit card verification number does not match number associated with card. Please re-enter number.");
}
}[/code]
why the triple equal in the second condition? Only one is needed.
Also, while we're at it,[URL="http://php.net/manual/en/mysqli.quickstart.prepared-statements.php"] read this[/URL]
No triple equals signs otherwise, yes, I think.
[QUOTE=Coment;45604590]why the triple equal in the second condition? Only one is needed.[/QUOTE]Yeah I just figured that out, leftovers from other bits of code.
How awesome is sublime?
Really considering using it. I currently use a web-based IDE that I like a lot, but sublime is really pretty and everyone seems to love it.
Only downside is that idk if I will be able to code at school anymore if I use it.
Worth it? I tried it out once and it seemed annoying to get used to but i'm willing to give it another chance.
If it makes a difference, I will be using a Mac.
[QUOTE=Shadaez;45594683]right here <-------[/QUOTE]
Managed to find a local graphic designer whom I really like working with so far.
Do you have a porfolio/resume? Send me a message!
If anyone else is interested, I am seeking an expert in PHP/MySQL. Bonus if you know a bunch of other web languages/server management. I can start the right candidate for the job at $20 / hour with an immediate raise based on demonstrated skill and attention to detail.
I'm running a xenforo forum, I've created a custom page and I have a form which sends me to the same page (url = "hostname.com/index.php?pages/dev/"), along with an added GET variable, so the final link would be something like: "hostname.com/index.php?pages/dev/&fileid=1". However I can't figure out how to set this up. If I put the above URL in the action field the browser strips the pages/dev and I land on the front page instead.
I've tried doing <input type="hidden" name="pages/dev/" value="">. However the browser encodes the slashes making it invalid.
[QUOTE=Donkie;45628401]I'm running a xenforo forum, I've created a custom page and I have a form which sends me to the same page (url = "hostname.com/index.php?pages/dev/"), along with an added GET variable, so the final link would be something like: "hostname.com/index.php?pages/dev/&fileid=1". However I can't figure out how to set this up. If I put the above URL in the action field the browser strips the pages/dev and I land on the front page instead.
I've tried doing <input type="hidden" name="pages/dev/" value="">. However the browser encodes the slashes making it invalid.[/QUOTE]
The slashes are most likely "SEO friendly URLs", meaning, mod_rewrite.
[QUOTE=Moofy;45603608][code]
<?php
if (isset($_POST["button"])) {
// Do this if the button was pressed
} else {
// Do this if the person tries to access the script without pressing the button
header("location: foo/bar.php");
exit(); /* Use exit(); or die(); under a header because PHP docs says so :V */
}
[/code][/QUOTE]
You die() after header(location) so that PHP doesn't continue to run the script, not just "because the docs say so"
It's a nice thing to remember if you forget to add a die() and wonder why your code still runs
[QUOTE=Cyberuben;45628510]The slashes are most likely "SEO friendly URLs", meaning, mod_rewrite.[/QUOTE]
Oh right! I tried putting "pages/dev" in the action field and it worked. Thanks for the hint
Any of you guys know why the first query here returns the result I want while the second one returns false?
I am executing the [B]fetch_wallet()[/B] function twice here:
[code]
if($this->pdo) {
foreach($this->methods as $method => $bool) {
if($bool) { $array[$method] = $this->fetch_wallet($method); }
}
}
[/code]
and this is the [B]fetch_wallet()[/B] function:
[code]
public function fetch_wallet($type) {
if($type == "darkrp") {
$query = "SELECT `wallet` FROM `darkrp_player` WHERE `uid`=:uid LIMIT 1";
}
elseif ($type == "pointshop") {
$query = "SELECT `points` FROM `pointshop_data` WHERE `uniqueid`=:uid LIMIT 1";
}
try {
$stmt = $this->pdo->prepare($query);
var_dump($stmt);
$stmt->execute(array(":uid" => $this->uniqueid));
$result = $stmt->fetchColumn();
return $result;
}
catch (PDOException $e) {
return $e->getMessage();
}
}
[/code]
The "pointshop" query returns false, while the darkrp query returns the data I'm expecting.
I have set the PDO's error attribute as so: [b]$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);[/b] so I should be getting an exception, however [B]$stmt->execute()[/B] can return false on failure.
[B]$stmt->errorInfo()[/B] returns this (which means nothing is wrong with the query):
[code]
array(3) {
[0]=> string(5) "00000"
[1]=> NULL
[2]=> NULL
}
array(3) {
[0]=> string(5) "00000"
[1]=> NULL
[2]=> NULL
}
[/code]
The actual query has been tested in phpMyAdmin and returns the result I'm expecting, so nothing's wrong with the query itself.
I've tried setting [B]$stmt->closeCursor();[/B] and [B]$stmt = null;[/B] with no avail.
I've dumped the [B]$stmt[/B] before and after [B]$stmt->execute()[/B] and there's no errors anywhere. Error reporting is set to E_ALL.
[URL="http://stackoverflow.com/questions/25214981/pdo-statement-returning-false"]Question on StackOverflow[/URL]
If I wanted to buy a domain, where would I go? I get the impression that godaddy isn't that good.
I personally like NameCheap
[QUOTE=Banana Lord.;45653341]I personally like NameCheap[/QUOTE]
Can confirm, namecheap is the way to go.
Speaking on domains, I decided to look into domains for a project I had been working on a few months ago. One of the domains I was looking at looks to be bought up by some company that just buys up domains to resell, or sit on, or something? The site in its current state is one of the extremely generic, plain sites that's just a half dozen or so text ads, and the whois is just "Admin Manager LLC" repeatedly.
I guess what I'm wondering is what's been done something I can get around to acquire the domain legally without paying exorbitant fees to the company who already "owns" the domain because some automated system decided it was a "worthwhile" domain to have?
Does anyone know how Norweigan mobile phone numbers usually look like across the country? Like here in Sweden [B]all[/B] our mobile numbers looks like 07X-XX-XX-XXX (so 10 numbers). Are there any exceptions in Norweigan mobile numbers that changes the amount of numbers it has?
I know Norweigan uses the [URL="http://en.wikipedia.org/wiki/E.164"]E.164[/URL] numbering plan, but that doesn't tell me much.
I also found [URL="http://en.wikipedia.org/wiki/Telephone_numbers_in_Norway#Mobile_numbers"]this[/URL], but I'm unsure if both exists and is still in use. I'm aware that the Norweigan country code is +47
[QUOTE=Svenskunganka;45667339]Does anyone know how Norweigan mobile phone numbers usually look like across the country? Like here in Sweden [B]all[/B] our mobile numbers looks like 07X-XX-XX-XXX (so 10 numbers). Are there any exceptions in Norweigan mobile numbers that changes the amount of numbers it has?
I know Norweigan uses the [URL="http://en.wikipedia.org/wiki/E.164"]E.164[/URL] numbering plan, but that doesn't tell me much.
I also found [URL="http://en.wikipedia.org/wiki/Telephone_numbers_in_Norway#Mobile_numbers"]this[/URL], but I'm unsure if both exists and is still in use. I'm aware that the Norweigan country code is +47[/QUOTE]
Always 9/4-XX-XX-XXX. (afaik noone uses M2M, i didn't even know what it was, it's ancient i think)
[editline]blegh[/editline]
M2M numbers are for mobile broadband, but not used in phones.
[QUOTE=TrinityX;45668413]Always 9/4-XX-XX-XXX. (afaik noone uses M2M, i didn't even know what it was, it's ancient i think)
[editline]blegh[/editline]
M2M numbers are for mobile broadband, but not used in phones.[/QUOTE]
Alright, thank you! In swedish numbers, when we add the country code (+46) we remove the 0, so instead of 070-12-34-567 we do +4670-12-34-567. Does that apply for norwegian numbers aswell?
So 9-00-00-000 becomes +47-00-00-000 or is it still +479-00-00-000? I'm guessing the latter for compatibility.
Thanks buddy!
[QUOTE=Svenskunganka;45668768]Alright, thank you! In swedish numbers, when we add the country code (+46) we remove the 0, so instead of 070-12-34-567 we do +4670-12-34-567. Does that apply for norwegian numbers aswell?
So 9-00-00-000 becomes +47-00-00-000 or is it still +479-00-00-000? I'm guessing the latter for compatibility.
Thanks buddy![/QUOTE]
Still +479/4-XX-XX-XXX, no matter what.
No problem :P
Im trying to ues the vertical timeline here [url]http://codyhouse.co/demo/vertical-timeline/index.html[/url]
But Im having a strange bug where when I scroll down it keeps sending my scroll bar back to the top of the bar, I have figured out its due to when items appear they cause the page heigh grow a little bit (You can tell as the middle bar doesnt stretch right to the bottom).
Anyone know of any simple ways to fix this?
[QUOTE=Richy19;45681446]Im trying to ues the vertical timeline here [url]http://codyhouse.co/demo/vertical-timeline/index.html[/url]
But Im having a strange bug where when I scroll down it keeps sending my scroll bar back to the top of the bar, I have figured out its due to when items appear they cause the page heigh grow a little bit (You can tell as the middle bar doesnt stretch right to the bottom).
Anyone know of any simple ways to fix this?[/QUOTE]
It doesn't even do that for me. Did you fix it yourself already? :v:
[editline]14th August 2014[/editline]
Wow early in the morning I'm dumb, I thought you made this yourself. Anyways, it doesn't do it for me still.
Can anyone recommend any good UK web hosting companies?
My current company is PoweredByPenguins.co.uk and I'm not satisifed with how long it's taking to reply now. I've been with them over a year and these last few months haven't been the best with them.
I own several domains so I need a company where the package will support multiple domains...
[QUOTE=ENG.jonny;45699474]Can anyone recommend any good UK web hosting companies?
My current company is PoweredByPenguins.co.uk and I'm not satisifed with how long it's taking to reply now. I've been with them over a year and these last few months haven't been the best with them.
I own several domains so I need a company where the package will support multiple domains...[/QUOTE]
IMO NFOServers has excellent webhosting.
[QUOTE=ENG.jonny;45699474]Can anyone recommend any good UK web hosting companies?
My current company is PoweredByPenguins.co.uk and I'm not satisifed with how long it's taking to reply now. I've been with them over a year and these last few months haven't been the best with them.
I own several domains so I need a company where the package will support multiple domains...[/QUOTE]
I don't get why people want their hosting in the country they live in. I live in Denmark, but I would never go with Danish hosting. I've had good shared hosting at [URL="http://lithiumhosting.com/"]Lithium[/URL] and now my VPS is at [URL="http://afterburst.com/"]Afterburst[/URL]. You should definitely go with Lithiumhosting or something, there's pretty much only good recommendations from in here if you go way back in the thread.
I also know gokiyono has his hosting at [URL="http://www.deroyalservers.com/"]DoRoyal (DeRoyal) servers[/URL], and he doesn't seem to have any problems either. (He also lives in Denmark.)
[QUOTE=Moofy;45705671]I don't get why people want their hosting in the country they live in.[/QUOTE]
So Americans shouldn't get hosting from America? It is a pretty odd advice
If you live in a country with a good host, you should go for it.
I also have one with with Namecheap on a server in the UK (which I will mainly use for email)
I haven't really met any problems there
[QUOTE=gokiyono;45705875]So Americans shouldn't get hosting from America? It is a pretty odd advice[/QUOTE]
Hows it odd? Also when I had with Lithium their server was in Amsterdam. And at Afterburst their datacenter is in Germany. I'm not saying I'm looking for hosting across the globe.
Sorry, you need to Log In to post a reply to this thread.