This is not a duplicate of Maximum execution time in phpMyadmin; this has nothing to do with phpmyadmin.
On my site, there is a form which sends POST data to a PHP script and loads a new page. When you submit the form, the page loads forever and then results in:
The XXX.XXX page isn’t working XXX.XXX is currently unable to handle
this request. HTTP ERROR 500
I thought it may be a traffic issue so I upgraded my hosting SSD and made the website only available to me to test it, but the problem still persisted. Here is my script:
<?php
$used_file = 'used.txt';
$codes_file = 'codes.txt';
# Generates a random unused code from the code file
function genCode() {
global $used_file, $codes_file;
$codes = file_get_contents($codes_file);
$codes = explode("\n", $codes);
$used = file_get_contents($used_file);
$used = explode("\n", $used);
foreach($codes as $code) {
if(!in_array($code, $used))
return $code;
}
}
# Generate error string from error code
function getError($err) {
switch($err) {
case 1: return 'No submit';
case 2: return 'Wrong password';
case 3: return 'No password';
}
}
# Adds generated code to the 'used' codes file
function append_used($code) {
global $used_file, $codes_file;
$str = $code . '\n';
file_put_contents($used_file, $str, FILE_APPEND);
}
# Get user's IP (for cookie handling)
function getIP() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
# Cookie handling
# Set a cookie for how many times the form has been submitted by user
$used = 0;
if(isset($_COOKIE['used_twice'])) {
$used = 3;
}
if(isset($_COOKIE['used_once']) && !isset($_COOKIE['used_twice'])) {
setcookie('used_twice', getIP(), time()+18000);
$used = 2;
}
if(!isset($_COOKIE['used_once'])) {
setcookie('used_once', getIP());
$used = 1;
}
# Check if all the POST data is correct
$password = $_POST['inputPassword'];
$submit = $_POST['submit'];
if(isset($password)) {
if($password == 'test123') {
if(isset($submit)) {
$code = genCode();
}
else
$err = 1;
} else
$err = 2;
} else
$err = 3;
# Now generate the new page
include 'web_functions.php';
getHead('Generated', 'Generated code');
getBody('Generated code');
?>
<img src="goback.png"></img>
<h2>Code Generated</h2>
<br/>
<?php
if(!isset($err) && isset($thecode) && $used == 1) {
?>
<center>
<div class="bs-component">
<div class="alert alert-dismissible alert-success">
<p>Your code is: </p> <strong> <?php echo $thecode; append_used($thecode); ?> </strong>
</div>
</div>
</div>
</center>
<?php
} elseif(isset($err)) {
?>
<center>
<div class="bs-component">
<div class="alert alert-dismissible alert-danger">
<p>There was an error:</p> <strong><?php echo getError($err); ?></strong>
</div>
</div>
</div>
</center>
<?php
} elseif(!isset($err) && $used != 1){
?>
<center>
<div class="bs-component">
<div class="alert alert-dismissable alert-danger">
<p>You can only use the code generator once every 5 hours. Please try again later.</p>
</div>
</div>
</div>
</center>
<?php } else { ?>
<div class="bs-component">
<div class="alert alert-dismissable alert-danger">
<p>There was an unexpected error. Please try again.</p>
</div>
</div>
</div>
<?php } ?>
<br/>
<br/>
<br/>
<?php closeTags();
getFooter(); ?>
</div>
</div>
</div>
</div>
What could be causing this issue?
Edit: The error log says:
PHP Fatal error: Maximum execution time of 60 seconds exceeded on line 13
Line 13 is within the foreach loop.
Related
I have two different user roles on my Website: Employer and Candidate. Every one had a type of profile but the profile from Candidate should see only employers and nobody else.
So I want a restriction in Wordpress like:
Employer CAN see Candidate
Candidate CAN'T see other Candidate
Candidate CAN see own Profile
This is controlled by a plugin but it seems to be broken BECAUSE:
Employer CAN see Candidate
Candidate CAN see other Candidate
Candidate CAN'T see own Profile
In the .php file from candidate profile is this code:
<?php
if (!$show_candidate_public_profile) {
if ($candidate->get_public_account() || get_current_user_id() == $candidate->get_author_id()) {
$check = 1;
} else {
$check = 2;
}
} else {
if (is_user_logged_in()) {
if ($show_candidate_public_profile == 2 && get_current_user_id() == $candidate->get_author_id()) {
if ($user->is_employer() && $candidate->get_public_account()) {
$check = 3;
} else {
$check = 4;
}
} else {
if ($candidate->get_public_account() || get_current_user_id() == $candidate->get_author_id()) {
$check = 1;
} else {
$check = 2;
}
}
} else {
$check = 0;
}
}
and the code for results right after code from above:
if (!$check) {
?>
<div class="iwj-alert-box">
<div class="container">
<span>
<?php echo sprintf(__('You must be logged in to view this page. Login here', 'iwjob'), add_query_arg('redirect_to', $candidate->permalink(), $login_page_id)); ?>
</span>
</div>
</div>
<?php
} else {
if ($check == 2) {
?>
<div class="iwj-alert-box">
<div class="container">
<span>
<?php echo esc_html__('This profile is not public now.', 'iwjob'); ?>
</span>
</div>
</div>
<?php } elseif ($check == 4) {
?>
<div class="iwj-alert-box">
<div class="container">
<span>
<?php echo esc_html__('This profile is not public or only employers can see.', 'iwjob'); ?>
</span>
</div>
</div>
<?php } else {
?>
<div class="iw-parallax" data-iw-paraspeed="0.1" style="background-image: url('<?php echo esc_url($cover_image_url); ?>');"></div>
<div class="iw-parallax-overlay"></div>
<div class="content-top">
<div class="container">
<div class="info-top">
<div class="candidate-logo">
The check 3 is the only one check showing profile.
I tried to change the "&&" "||" "==" but i can't figure it out how this logic work.
So much php is too much for me. I have asked the Plugin creator but I am always waiting 5 days to reply and I need it now.
I would be very happy if someone would help me with this.
Thank you very much!
Martin
This code should work according to the behavior you have described(of course it will depend on the good functionality of your plugin). I had to take off some conditions since I don't know what they are and also you didn't provide further details, if you need them you have to add later, but this is quite simple and this code is much more readable.
First portion:
<?php
if(!is_user_logged_in())
$check=false; //if user is not logged in check is false
else
{
//check if user is employer or if is the profile owner
if ($user->is_employer() || get_current_user_id() == $candidate->get_author_id())
$check = 1; //sets 1 if allowed
else
$check = 2; //sets 2 if denied
}
?>
Second portion:
if (!$check) //is check false? then show login message
{
?>
<div class="iwj-alert-box">
<div class="container">
<span>
<?php echo sprintf(__('You must be logged in to view this page. Login here', 'iwjob'), add_query_arg('redirect_to', $candidate->permalink(), $login_page_id)); ?>
</span>
</div>
</div>
<?php
}
else //check it's not false, so do more tests
{
if ($check == 2) //if equals 2 then shows access denied message
{
?>
<div class="iwj-alert-box">
<div class="container">
<span>
<?php echo esc_html__('This profile is not public now or only employers can see.', 'iwjob'); ?>
</span>
</div>
</div>
<?php
}
elseif($check == 1) //user is profile owner or is an employer, show everything
{
?>
<div class="iw-parallax" data-iw-paraspeed="0.1" style="background-image: url('<?php echo esc_url($cover_image_url); ?>');"></div>
<div class="iw-parallax-overlay"></div>
<div class="content-top">
<div class="container">
<div class="info-top">
<div class="candidate-logo">
If you want more tests, like about profile being public or not, you really have to provide more information. I hope it can help you.
I have a problem with the register page in PHP language. When I click the submit button the form is submitting but no data is storing in the database. And can not use the registered user to login into the site. The same codes are working properly in the local server (Wampp server) but not working in the website.
these are the codes:
<?php
require_once("../includes/functions.php");
$sess_start->start_session(false);
if(check_login(1, $sess_start->get_dbhandler()) == true)
{
header('Location: userportal.php');
}
else
{
if (!empty($_POST['RegisterFname']) || !empty($_POST['RegisterLname']) || !empty($_POST['RegisterEmail']) || !empty($_POST['RegisterUsername']) || !empty($_POST['RegisterPassword']) || !empty($_POST['RegisterRPassword']) || !empty($_POST['RegisterDob']) || !empty($_POST['RegisterAddress']) || !empty($_POST['RegisterRegion']) || !empty($_POST['RegisterCountry']) || !empty($_POST['RegisterPhone']))
{
if (!empty($_POST['RegisterFname']) && !empty($_POST['RegisterLname']) && !empty($_POST['RegisterEmail']) && !empty($_POST['RegisterUsername']) && !empty($_POST['RegisterPassword']) && !empty($_POST['RegisterRPassword']) && !empty($_POST['RegisterDob']) && !empty($_POST['RegisterAddress']) && !empty($_POST['RegisterRegion']) && !empty($_POST['RegisterCountry']) && !empty($_POST['RegisterPhone']))
{
if (($_POST['RegisterPassword'] == $_POST['RegisterRPassword']))
{
if (strlen($_POST['RegisterRPassword']) >= 8)
{
$registeruser = new user();
$registeruser->nickname = clean_string($sess_start->get_dbhandler(), $_POST['RegisterUsername']);
$registeruser->sql = mysqli_query($sess_start->get_dbhandler(), "SELECT * FROM `users` WHERE n_name = '$registeruser->nickname'");
if (mysqli_num_rows($registeruser->sql) == 0)
{
$registeruser->fname = clean_string($sess_start->get_dbhandler(), $_POST['RegisterFname']);
$registeruser->lname = clean_string($sess_start->get_dbhandler(), $_POST['RegisterLname']);
$registeruser->email = clean_string($sess_start->get_dbhandler(), $_POST['RegisterEmail']);
$registeruser->password = $_POST['RegisterRPassword'];
$registeruser->password = hash('sha512', $registeruser->password);
$registeruser->dob = clean_string($sess_start->get_dbhandler(), $_POST['RegisterDob']);
$registeruser->addr = clean_string($sess_start->get_dbhandler(), $_POST['RegisterAddress']);
$registeruser->state = clean_string($sess_start->get_dbhandler(), $_POST['RegisterRegion']);
$registeruser->country = clean_string($sess_start->get_dbhandler(), $_POST['RegisterCountry']);
$registeruser->phone = clean_string($sess_start->get_dbhandler(), $_POST['RegisterPhone']);
$registeruser->regtime = time();
$registeruser->sql = mysqli_query($sess_start->get_dbhandler(), "INSERT INTO `users` (f_name, l_name, email, n_name, password, age, addr, state, country, phone, l_login, r_time) VALUES ('$registeruser->fname', '$registeruser->lname', '$registeruser->email', '$registeruser->nickname', '$registeruser->password', '$registeruser->dob', '$registeruser->addr', '$registeruser->state', '$registeruser->country', '$registeruser->phone', '0', '$registeruser->regtime')");
if (!empty($_GET['RegisterPromo']))
{
$registeruser->coupon = clean_string($sess_start->get_dbhandler(), $_POST['RegisterPromo']);
$registeruser->sql = mysqli_query($sess_start->get_dbhandler(), "UPDATE `users` SET promo = '$registeruser->coupon' WHERE n_name = '$registeruser->nickname'");
}
$_SESSION['RegisterUserError'] = 5;
header('Location: register.php');
}
else
{
$_SESSION['RegisterUserError'] = 4;
header('Location: register.php');
}
}
else
{
$_SESSION['RegisterUserError'] = 3;
header('Location: register.php');
}
}
else
{
$_SESSION['RegisterUserError'] = 2;
header('Location: register.php');
}
}
else
{
$_SESSION['RegisterUserError'] = 1;
header('Location: register.php');
}
}
else
{
echo '
meta tages and links for the stylesheets
';
?>
<?php
?>
<div class="container" id="registration-form">
<div class="image"></div>
<form role="form" class="form-signin" method="post" action="<?php echo clean_url($_SERVER['PHP_SELF']); ?>">
<section class="panel">
<div class="panel-body">
<?php
if (isset($_SESSION['RegisterUserError']))
{
if ($_SESSION['RegisterUserError'] == 1)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Fill all mandatory fields(*) for completing user registeration</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 2)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Entered passwords do not match</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 3)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Passwords must be 8 or more character longer</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 4)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>There is already a user exist with this same username</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 5)
{
?>
<div class="alert alert-success fade in">
<strong>Successfully completed the user registeration. However, your account is not verified unless you complete "Know your customer" process after login to your account.</strong>
</div>
<?php
}
else
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Unexpected error occured</strong>
</div>
<?php
}
unset($_SESSION['RegisterUserError']);
}
else
{
?>
<div class="alert alert-success fade in">
<strong>Fields indicated using * are mandatory in registeration</strong>
</div>
<?php
}
?>
<div class="frm">
inputs here
</form>
<div class="form-footer">
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-5">
<i class="fa fa-check"></i> Sign In
</div>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php
}
}
?>
if it is working on your local server, then check your web hosting service. Most Service provider will ask you to the these three things :
1.Create the database
2.Create a database user
3.Assign the user to the database
These steps could be confusing depending on your host and is usually carried out in your cpanel database page or use the database creation wizard if available.
I have a number of fields that have numerous validations from codeigniter validations. but now its showing one single validation error flash that is truly validated message
Here is my controller block code
public function customer_upd()
{
extract($_POST);
$err = '';
$date1 = $_POST['cust_upd_bd'];
$date2 = $_POST['cust_upd_dom'];
if($date2 != "") {
$datediff = (strtotime($date2) - strtotime($date1));
$res = floor($datediff / (60 * 60 * 24));
if ($res == " ") {
$err .= "Please Enter a Date";
} elseif ($res < 365) {
$err .= "Child marriage is prohibited";
}
if ($err != '') {
$_SESSION['dateerror'] = $err;
redirect('customer/edit/'.$_POST['ctmr_upd_id']);
}
}
$original_value1 = $this->db->query("SELECT customer_email FROM customer WHERE id = ".$_POST['ctmr_upd_id'])->row()->customer_email ;
if($_POST['cust_upd_email'] != $original_value1) {
$this->session->set_flashdata('add_failed','Email id must be unique & valid email address.');
$is_unique = '|is_unique[customer.customer_email]';
} else {
$is_unique = '';
}
$original_value2 = $this->db->query("SELECT customer_mobile FROM customer WHERE id = ".$_POST['ctmr_upd_id'])->row()->customer_mobile ;
if($_POST['cust_upd_mobile'] != $original_value2) {
$this->session->set_flashdata('add_failed','Mobile no must be unique & exact 10 digit numeric length. ');
$is_phoneunique = '|is_unique[customer.customer_mobile]';
} else {
$is_phoneunique = '';
}
$this->form_validation->set_rules('cust_upd_email', 'Email', 'required|valid_email|trim'.$is_unique);
$this->form_validation->set_rules('cust_upd_mobile', 'Mobile', 'required|exact_length[10]|is_natural|trim'.$is_phoneunique);
$this->form_validation->set_rules('cust_upd_name', 'Customer name', 'trim|required|min_length[3]|callback_customAlpha');
$this->session->set_flashdata('cust','The Customer field must be at least 3 characters in length. ');
$this->form_validation->set_rules('cust_upd_bd', 'Date of birth', 'regex_match[(0[1-9]|1[0-9]|2[0-9]|3(0|1))-(0[1-9]|1[0-2])-\d{4}]');
$this->form_validation->set_rules('cust_upd_dom', 'Date of marriage', 'regex_match[(0[1-9]|1[0-9]|2[0-9]|3(0|1))-(0[1-9]|1[0-2])-\d{4}]');
if ($this->form_validation->run() ) {
$userdata = $this->session->userdata();
$userId = $userdata['id'];
if (!$userId):
redirect(site_url());
endif;
extract($_POST);
print_r($_POST); exit;
$data = array(
'customer_name' => ucwords($_POST['cust_upd_name']),
'birth_date' => $_POST['cust_upd_bd'],
'anniversery_date' => $_POST['cust_upd_dom'],
'customer_mobile' => $_POST['cust_upd_mobile'],
'customer_email' => $_POST['cust_upd_email'],
'status' => $_POST['cust_upd_status'],
'address' => $_POST['ctmr_address'],
'cat_type' => $_POST['file_cat']
);
$userdata = $this->session->userdata();
$userId = $userdata['id'];
$this->db->where('user_id', $userId);
$this->db->where('id', $_POST['file_cat']);
$this->db->where('cat_status', 'Enable');
$get_file = $this->db->get('category');
$res_file = $get_file->num_rows();
if($res_file >0){
$userdata = $this->session->userdata();
$userId = $userdata['id'];
$this->db->where('user_id', $userId);
$this->db->where('id', $_POST['ctmr_upd_id']);
$ctmr_upd = $this->db->update('customer', $data);
} else {
$this->session->set_flashdata('edit_failed','Something went wrong.');
redirect('customer/edit/'.$_POST['ctmr_upd_id']);
}
redirect(site_url() . '/customer');
} else {
redirect('customer/edit/'.$_POST['ctmr_upd_id']);
}
}
And here is my view code
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<?php if($error = $this->session->flashdata('add_failed')): ?>
<div class="row">
<div class="col-lg-9">
<div class="alert alert-dismissible alert-danger col-md-offset-4">
<?php echo $error; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if($error1 = $this->session->flashdata('edit_failed')): ?>
<div class="row">
<div class="col-lg-9">
<div class="alert alert-dismissible alert-danger col-md-offset-4">
<?php echo $error1; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if($error2 = $this->session->flashdata('cust')): ?>
<div class="row">
<div class="col-lg-9">
<div class="alert alert-dismissible alert-danger col-md-offset-4">
<?php echo $error2; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if($_SESSION['dateerror']){
echo '<div class="alert alert-danger col-sm-7 col-md-offset-3" role="alert">'.$_SESSION['dateerror'].'</div>';
unset($_SESSION['dateerror']);
}
?>
And here is a snap
Whenever i tries to submit with their validate data, its showing this above error flash message.
i tried many times but unable to achieve any success.
Please guide me and tell me where am i going wrong?
Use below mentioned code to retrieve all flashdata.
$this->session->flashdata();
It will return array with all flashdata, simply omit the key parameter.
Let me know if it not works.
I am working on a template a friend given me ages ago. However, this is the code of the main page:
<div class="span4">
<div class="widget">
<div class="navbar"><div class="navbar-inner"><h6>fame</h6></div></div>
<div class="well body">
<center>
<div class="fame">
<?php include("cache/fame.php"); ?>
</div>
</center>
</div>
</div>
</div>
In this fame.php, there's a line of code:
if(!isset($_GET['enable']) && !isset($argv[1]) == "enable")
{
echo 'Invalid request';
return;
}
And it always return Invalid request from the main page.. So, what is this last code paragraph for?
if(!isset($_GET['enable']) && !isset($argv[1]) == "enable")
{
echo 'Invalid request';
return;
}
The above code is used in 2 scenarios:
One is the script mode for which the argument $argv is used.
Second mode is as server code where Global params are being passed i.e $_GET.
Just change the code to handle both the scenarios.
if(php_sapi_name() == 'cli' && (!isset($argv[1]) || ( isset($_GET['enable']) && $argv[1] !== "enable"))
{
echo 'Invalid request';
return;
}
else
{
if(!isset($_GET['enable'])
{
echo 'Invalid request';
return;
}
}
I'm currently using sphider on one of my websites, my questions is how can I break the results page into 2 parts to add a 200px break to place a ad slot.
Code:
<?php
extract($search_results);
?>
<?php if ($search_results['did_you_mean']){?>
<div id="did_you_mean">
<?php echo $sph_messages['DidYouMean'];?>: <?php print $search_results['did_you_mean_b']; ?>?
</div>
<?php }?>
<?php if ($search_results['ignore_words']){?>
<div id="common_report">
<?php while ($thisword=each($ignore_words)) {
$ignored .= " ".$thisword[1];
}
$msg = str_replace ('%ignored_words', $ignored, $sph_messages["ignoredWords"]);
echo $msg; ?>
</div>
<?php }?>
<?php if ($search_results['total_results']==0){?>
<div id ="result_report">
<?php
$msg = str_replace ('%query', $ent_query, $sph_messages["noMatch"]);
echo $msg;
?>
</div>
<?php }?>
<?php if ($total_results != 0 && $from <= $to){?>
<div id ="result_report">
<?php
$result = $sph_messages['Results'];
$result = str_replace ('%from', $from, $result);
$result = str_replace ('%to', $to, $result);
$result = str_replace ('%all', $total_results, $result);
$matchword = $sph_messages["matches"];
if ($total_results== 1) {
$matchword= $sph_messages["match"];
} else {
$matchword= $sph_messages["matches"];
}
$result = str_replace ('%matchword', $matchword, $result);
$result = str_replace ('%secs', $time, $result);
echo $result;
?>
</div>
<?php }?>
<?php if (isset($qry_results)) {
?>
<div id="results">
<!-- results listing -->
<?php foreach ($qry_results as $_key => $_row){
$last_domain = $domain_name;
extract($_row);
if ($show_query_scores == 0) {
$weight = '';
} else {
$weight = "[$weight%]";
}
?>
<?php if ($domain_name==$last_domain && $merge_site_results == 1 && $domain == "") {?>
<div class="idented">
<?php }?>
<b><?php print $num?>.</b> <?php print $weight?>
<?php print ($title?$title:$sph_messages['Untitled'])?><br/>
<div class="description"><?php print $fulltxt?></div>
<div class="url"><?php print $url2?> - <?php print $page_size?></div>
<?php if ($domain_name==$last_domain && $merge_site_results == 1 && $domain == "") {?>
[ More results from <?php print $domain_name?> ]
</div class="idented">
<?php }?>
<br/>
<?php }?>
</div>
<?php }?>
<!-- links to other result pages-->
<?php if (isset($other_pages)) {
if ($adv==1) {
$adv_qry = "&adv=1";
}
if ($type != "") {
$type_qry = "&type=$type";
}
?>
<div id="other_pages">
<?php print $sph_messages["Result page"]?>:
<?php if ($start >1){?>
<?php print $sph_messages['Previous']?>
<?php }?>
<?php foreach ($other_pages as $page_num) {
if ($page_num !=$start){?>
<?php print $page_num?>
<?php } else {?>
<b><?php print $page_num?></b>
<?php }?>
<?php }?>
<?php if ($next <= $pages){?>
<?php print $sph_messages['Next']?>
<?php }?>
</div>
<?php }?>
<div class="divline">
</div>
I'm also not aware of a live PHP code editor, if you know of one please comment and share so I can add a link!
Presuming $from and $to are the result numbers, so you're displaying "Showing results 10 to 30 of 100" for example:
<div id="results">
<!-- results listing -->
<?php $adbreak = ($to - $from) / 2;
<?php foreach ($qry_results as $_key => $_row){
<?php if ($adbreak == 0) { ?>
<div id="results-adbreak">
<img src="buy-a-car.jpg" alt="one careful owner!" />
</div>
<?php }
$adbreak--;
?>
// rest of your code
This will put a div approximately (give or take one) half way down your page of results. You can obviously replace the ad with a call to whatever you want.
adding something like:
<?php $adbreak = ($to - $from) / 2;
<?php if ($adbreak < 5) $adbreak = -1; ?>
will ensure that it doesn't display at all if the results list is too short.
If you don't know $to and $from in advance, you can still do it, but you'll have to calculate the equivalent from the query result first.