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;
}
}
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.
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.
I would like to know how I can do to change the links depending on where I am on my site?
For example, I would like that when I click on "Sign In", it is like this:
Forums > Sign In
http://prntscr.com/47d04a
container.php:
<div class="wrapper">
<div id="container">
<div id="breadcrumb_top">
<div class="breadcrumb_links">
<ul>
<li class="forums">
Forums
</li>
</ul>
</div>
</div>
<?php
if(strpos($_SERVER["REQUEST_URI"], "index") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Forums</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "members") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Members</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "sign_up") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Sign Up</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "sign_in") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Sign In</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "change_theme") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Change Theme</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "contact_us") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Contact Us</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "help") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Help</h1>";
/* Code here. */
}
?>
<?php
if(strpos($_SERVER["REQUEST_URI"], "rules") !== false) {
echo "<h1 style='margin-bottom: 15px;'>Rules</h1>";
/* Code here. */
}
?>
<div id="breadcrumb_bottom">
<div class="breadcrumb_links">
<ul>
<li class="forums">
Forums
</li>
</ul>
</div>
</div>
</div>
</div>
I would like that everything be automated depending on where I am. If I click on "Members" in the top_bar, I would like that "Forums" in the breadcrumb should be replaced by "Members", etc.
Thanks.
At the top of my pages I'll create some PHP variables or constants that describe what the page name, parent and title are and then use a function to determine what page I'm on by what's defined/set.
This is an idea of what it's like.
<?php
define('PARENT','Blog'); // the site section/parent
define('PAGE','Posts'); // the child page under the site section
$page_title = 'My Blog'; // the page's title
function active($str, $submenu='') {
if(!defined(PARENT) || !defined(PAGE)) {
return false;
}
if($submenu) {
if($str == PARENT) {
return ' visible';
}
} else {
if($str == PARENT || $str == PAGE) {
return ' class="active selected"';
}
}
return false;
}
echo $page_title;
?>
<ul class="submenu<?php echo active('Blog', 'submenu') ?>">
<li<?php echo active('Posts') ?>>
Posts
</li>
</ul>
I have tried
if ($row_products['psText'] != empty) {
and
if (!empty($row_products['psText'])) {
and
if (!is_null($row_products['psText'])) {
None of them work. However, if I echo out the echo $row_products['psText'], it has texts in there. Am I missing something here?
Okay, I'm updating my code. Below is the whole block of code. Perhaps my logic is wrong and not the code.
<?php do { ?>
<?php if($row_products['psLeft'] != ""){ ?>
<div id="left"><?php echo $row_products['psLeft']; ?></div>
<?php } if($row_products['psCenter'] != ""){ ?>
<div id="center"><?php echo $row_products['psCenter']; ?></div>
<? } if($row_products['psRight'] != ""){ ?>
<div id="right"><?php echo $row_products['psRight']; ?></div>
<? } if($row_products['psText'] != NULL && $row_products['psText'] != '' && !empty($row_products['psText'])){?>
<p>
<?php echo $row_products['psText']; ?>
</p>
<?php } else {echo 'Outside texts.'.$row_products['psText'];}?>
<?php } while ($row_products = mysql_fetch_assoc($products)); ?>
Try this
if ($row_products['psText'] != '') {
OR
if (strlen($row_products['psText']) !=0) {
OR
if(!empty($row_products['psText']))
I hope this helps you!!
You might try:
if ($row_products['psText'] != "") {
maybe following works:
if($row_products['psText'] != NULL && $row_products['psText'] != "" && !empty($row_products['psText'])){