So, now, I can't seem to get this to work. What I'm trying to accomplish is to get the success message to show up, but it just doesn't work for some odd reason.
I'm using the php-login project (minimal) available here: http://www.php-login.net/
This is the basic PHP part.
<?php
//die(print_r(get_defined_vars(), true));
include("includes/database.incl.php");
require_once("includes/Login.php");
$login = new Login();
if (isset($login)) {
if ($login->errors) {
if ($login->messages) {
foreach ($login->messages as $message) {
die("success");
}
}
foreach ($login->errors as $error) {
echo $error;
}
}
} else {
echo "nope";
}
$login = null;
?>
Right now, I'm using a program to send login details (log_name, log_password) using a POST request. It works and echos the errors if I deliberately put in wrong details, but once I type the details, it returns nothing. Even if I type incorrect details after, it still presents me with nothing.
Thanks in advance.
It turns out that it was a web server problem.
I was originally using XAMPP, and now that I switched to WAMP, it works.
Thanks for the help, everyone.
Related
I'm hosted with Smarthosting, they used cloud based hosting which delivers faster loading times - great!
But I have a snag.
I'm setting some sessions via PHP in a seperate file...
<?php
session_start();
if(filter_var($_POST['question_1'], FILTER_VALIDATE_INT)) {
$_SESSION['question_1'] = addslashes($_POST['question_1']);
}
if(filter_var($_POST['question_2a'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2a'] = addslashes($_POST['question_2a']);
}
if(filter_var($_POST['question_2b'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2b'] = addslashes($_POST['question_2b']);
}
if(filter_var($_POST['question_2c'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2c'] = addslashes($_POST['question_2c']);
}
if(filter_var($_POST['question_2d'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2d'] = addslashes($_POST['question_2d']);
}
if(filter_var($_POST['question_2e'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2e'] = addslashes($_POST['question_2e']);
}
if(filter_var($_POST['question_2f'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2f'] = addslashes($_POST['question_2f']);
}
if(filter_var($_POST['question_2g'], FILTER_VALIDATE_INT)) {
$_SESSION['question_2g'] = addslashes($_POST['question_2g']);
}
?>
Then later on I access another PHP file which puts these into a JSON string...
<?php
session_start();
echo json_encode($_SESSION);
?>
This works fine, however, until I call the JSON via Ajax...
$.getJSON( "retrieve-variables.php", function( data ) {
var items = [];
...etc....
});
It's not pulling the most recent session data, it seems to pull back the session data from previous attempts. Is this to do with the cloud hosting? Or some other issue? Is there a way I can disable caching for this particular file and/or entire directory?
Thanks for listening.
EDIT: If I access the PHP retrieval file directly, then hard refresh it (CTRL+F5), and then go through the form again, it will ignore the answers I've selected and enter the data for that hard refresh I did
I found out how to fix this, in case anyone stumbles upon this post.
I simple added cache:"false" to the ajax get request.
I'm experiencing a very odd problem. Everything works as expected on my local host. When I upload to a live server, the page just cuts off right where I'm including a file. Just white space beneath it. Nada...
The line that breaks is:
<? require_once('inc/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>
And the file being included is:
<?php
/*///////////////////////////////////////////////////////////////////////
Part of the code from the book
Building Findable Websites: Web Standards, SEO, and Beyond
by Aarron Walter (aarron#buildingfindablewebsites.com)
http://buildingfindablewebsites.com
Distrbuted under Creative Commons license
http://creativecommons.org/licenses/by-sa/3.0/us/
///////////////////////////////////////////////////////////////////////*/
function storeAddress(){
// Validation
if(!$_GET['email']){ return "No email address provided"; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
return "Email address is invalid";
}
require_once('MCAPI.class.php');
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('xxxxxxx');
// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "xxxxxx";
if($api->listSubscribe($list_id, $_GET['email']) === true) {
// It worked!
// return 'Success! Thank You!';
echo '<script> window.location.href = "thank-you.php"; </script>';
}
else
{
// An error ocurred, return error message
return 'Error: ' . $api->errorMessage;
}
}
// If being called via ajax, autorun the function
if($_GET['ajax']){ echo storeAddress(); }
?>
The only thing edited in the above code is the API key and List ID.
its because is missing parentesis on your if condition.
require_once('inc/store-address.php');
if($_GET['submit'] **)** {
echo storeAddress();
}
It seems there was an error. It was working on my local server because there wasn't an error.
I was using filezilla do upload my content. For some reason it appears to be an encoding issue when uploading.
I don't know if I should delete this question or answer to help someone else with the problem later on so I chose the later.
I manually uploaded my file and guess what, it works!
So on one page my users check a box and type agree in an input field to proceed to the next page, I am trying to use session cookies to stop people bypassing this by typing the URL however when you proceed to the next page it just displays blank? i have tried tests such as using Echo to display text at the beginning of the script and have enabled error reporting but the page still just displays white? any ideas why?
Check Box and Input Page php:
<?php
if(isset($_POST["terms"])&&isset($_POST["agree"])) {
$agree = $_POST["agree"];
$validated = false;
if($agree=="agree") $validated = true;
if($validated) {
setcookie("agree",($agree));
header("Location: nextpgae");
} else {
header("Location: homepage");
}
}
?>
Page it leads to that is displaying blank's php:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$validated = false;
if(isset($_COOKIE["agree"])){
$agree = $_COOKIE["agree"];
if(&$agree==("agree")) $validated = true;
}
if($validated) {
} else {
header("Location: homepage");
?>
A blank page is usually symptomatic of a server error. Frequently, it indicates a syntax error in your PHP code. Your server error log will tell you exactly what is going on, but in this case you have missed a closing } after this line
header("Location: homepage");
You should implement tokens for this kind of procedure. This may help you: http://forum.codecall.net/topic/58268-form-tokens-with-php/
I am developing a facebook app and I have some php functions. When I call one of them, the request is sent over and over and goes in an infinite loop. I have no clue why.
My function is:
function writeJSON()
{
if (!$user_id) {
echo "User not logged in";
}
else
{
global $arrayForJSON,$user_id;
$arrayForJSON['a']='b';
var_dump($arrayForJSON);
}
}
If I run it just like that, it will show
array (size=1) 'a' => string 'b' (length=1)
Which is correct. However if I run another function that adds more elements to the$arrayForJSON, it goes into the loop. The other function is:
function getLikes()
{
global $facebook,$user_id,$arrayForJSON;
$likes=NULL;
if($user_id) {
try {
if(is_null($likes))
$likes = idx($facebook->api('/me/likes'), 'data', array());
if ($likes) {
$arrayForJSON['likes']=$likes;
}
}
catch(FacebookApiException $e){
echo error_log($e);
}
echo "done";
var_dump($arrayForJSON);
}
else
echo "Not working";
Please give a helping hand, I've been working on that for some time and I have no clue what should I do.
If I call writeJSON() before calling getLikes(), it works. If I call it afterwards, it goes into the loop. I obviously need to call it after calling getLikes, because I need that data to be written to the JSON file
There is no place whatsoever where there could be any looping or recursion in both of your functions. Most likely your getLikes() function is being called repeatedly from somewhere else that's outside of the posted code.
There is a somewhat similar question here, that suggests that Facebook authorization might be at fault somehow. I'm including the link here because maybe there is some code you're not showing that may cause the same behavior. However, it couldn't be caused just by the code you have posted.
Im adding php inside an article using DirectPHP plugin.
My goal is to create a script that will include a file with text when the user has member = true; and when not to not show anything.
I have added this piece of code in a module in the top next to the logo:
<?php
if ($user =JFactory::getUser()->guest)
{
$member = false;
echo "Welcome guest, sign up and read nice quotes";
}
else
{
$member = true;
$user =& JFactory::getUser();
echo "Welcome " . $user->username;
}
?>
I have set member = true; now that the person has signed in. If he isnt signed in its on false.
Then inside the article I have:
<?php
if ($member == false)
{
$file = file_get_contents ('quotes/quotes.html');
echo $file;
}
?>
<hr id="system-readmore" />
<?php
if ($member == true)
{
include_once JPATH_SITE.'/quotes/random.php';
echo ShowQuotes();
}
?>
I cant find the problem making this not run. The quotes are shown for both $member = false; and $member = true; Are includes always being parsed despite the if statement? Same goes for file_get_contents? I tried to see if the $member declaration from the header is being kept within the parsing and wrote:
<?php
if ($member = true)
{
echo "Logged in";
}
?>
and it worked good so the problem is within the include_once and file_get_contents, I tried to pinpoint it as much as I can.
Thanks in advance for your help!
This is probably your issue:
if ($member = true)
{
echo "Logged in";
}
This is always assigning the value of true to $member.
Also here:
if ($user =JFactory::getUser()->guest)
You might have the same assignment problem (not sure if you intended to set $user and do a conditional at one here.
I might suggest getting in the habit of writing condditionals like this:
if (true === $member) { ... }
By inverting the order of the items, if you ever accidentally type = instead of == or ===, then you will get an error, instead of having the code silently perform unexpectedly.
You seem to have a scope issue here: you are declaring $member in a module, but $member won't be available to the article: and php will evaluate ($something == false) to always succeed if $something is undefined, if you want to check if a variable is really false you need to use ($something===false). Read more here: http://www.php.net/manual/en/language.types.boolean.php
That being said, since there is no real overhead to JFactory::getUser()->guest, just use that as well in you article!
btw, enable notices in your php configuration (either on screen or to a log file) and make sure you read that as you develop, it will tell you whatever is wrong, developing without seeing the errors is a guessing game, you can only bang your head against the wall so many times... you eventually need to switch on the light :-)