why Php increment count session twice per page load? - session

My wordpress php script is incremented by two instead one.
++$_SESSION['visitor'] is incremented by two !
In functions.php
if ( !isset( $_SESSION['visitor'] ) ) $_SESSION['visitor'] = 1; else ++$_SESSION['visitor'];
I have to do this in echo to have Session + 1 otherwise I get Session + 2: In any php file
`<?php echo --$_SESSION['visitor'] ; ?>`
I don't know what can cause this.
If I increment when I echo The session is well incremented by 1 , why ?.
if ( !isset( $_SESSION['visitor'] ) ) $_SESSION['visitor'] = 1; else $_SESSION['visitor'];
<?= $_SESSION['visitor'] .' + ' . ++$_SESSION['visitor']; ?>
The increment add well +1 only on any php file inside theme but add +2 every time using it in functions.php. For both I use the same syntax ++$_SESSION['visitor']
I have add params to session to allow subdomains in functions.php:
session_set_cookie_params(0, '/', '.website.com');

Related

codeigniter error:syntax error, unexpected '1' (T_LNUMBER)

ajax driven search(date range is input).
search is working properly however when I am trying to convert status(value 1 & 2 is stored in database) as ON or OFF. I'm getting this error, when I change if ('.$row->status.' === '1' ) to if ('.$row->status.' === 1 ) output is
if (1 === 1 ) else if (2 === 1 ) else if (1 === 1 ) else
foreach ($query as $row)
{
$output .= '
<tr>
if ('.$row->status.' === '1' ) //err
<td>ON</td>
else
<td>OFF</td>
</tr>
You have to go through something like the following thought process...
"I want to output a string "On" or "Off" based on the result of $row->status.
So first you need to determine what the string , let's call it $on_off.
Then you need to create your string segment based upon $on_off.
foreach ($query as $row)
{
// Determine the ON/OFF string to output
$on_off = ($row->status)?'ON':'OFF';
// Create the String Segment.
$output .= '<tr><td>';
$output .= $on_off;
$output .= '</td></tr>';
// Whatever else is here...
}
The reason I have broken $output into 3 commands is to help break up the table tags into something a bit more readable and less prone to mistakes.

Php Generate random number without repeat

$C = $_POST['Cc'];
$X = $_POST['X'];
$CX = $_POST['Cc'] . $_POST['X'];
$NC = preg_replace_callback("/x/" ,function() {return rand(0,9);}, $CX);
$New = $NC ;
$NNew = str_repeat($New,10);
echo $NNew;
what's wrong when i output it , it gives me the same number How to make It Don't Give me the same Numbers ??
It's basically you are not changing the seed for the rand method. Each time it's getting same seed and generating same number.
Read this PHP manual : http://php.net/manual/en/function.srand.php
Check the code snippet below:
<?php
// seed with microseconds
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return $sec + $usec * 1000000;
}
srand(make_seed());
$randval = rand(0,9);
echo $randval;
?>
Or you can use mt_rand() which is seeded differently on each execution.

Laravel Function at Scheduler

I have a laravel 5.2 project and i want to run laravel scheduler by specified time from database data, so i create schedule kernel like this :
protected function schedule( Schedule $schedule )
{
// Run proposal schedule to generate albums
$proposals = Proposal::whereStatus( true )->whereGenerated( false )->get();
foreach ( $proposals as $key => $proposal ) {
$time = date( 'i G ', strtotime( $proposal->duedate ) );
$send_date = date( $time . 'j n * Y', strtotime( $proposal->created_at . ' + ' . $proposal->timeout . ' days' ) );
$schedule->call( function() use( $proposal ) {
$proposal->generateAlbums();
} )->cron( $send_date );
}
}
And it's work fine, until i reset my migration and try to migrate from the begining, i got an error like this
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "proposals" does not exist
So i think it's not good if i place my code there, right??
where should i place my code for this??
Or it's already right and what i need just to check if database table are exists or not??
I need best solution to code just the way laravel provide..
You can check if table exists or not by
if (Schema::hasTable('proposals')) {
//Your code which needs to execute
}

admin session user edit posts

In database I have a column acc_type as int, and I'm trying to code this if $_SESSION['accountTpye']==1 then allowed this user to edit the other users posts,
And should I use and instead of && ? " or , || ".
Example code:
if(isset($_SESSION['username']) && ($_SESSION['username']==$dnn2['author'] || $_SESSION['accc_type']==1['username'])) {
echo "<a href='edit.php'>Edit</a>";
}
i think this will resolve your problem :
if(isset($_SESSION['username']){
if( ($_SESSION['username']==$dnn2['author']) || ($_SESSION['acc_type']==1) ){
echo "<a href='edit.php'>Edit</a>";
}
}
if((isset($_SESSION['username']) && $_SESSION['username']==$dnn2['author']) || $_SESSION['acc_type']==1){
echo "<a href='edit.php'>Edit</a>";
}
This part doesn't make sense:
$_SESSION['acc_type']==1['username']
If you just remove that last ['username'] and then wrap the session username part to be the first part of the conditional so the acc_type one does not depend on it then things should be ok
UPDATE:
In your login.php file locate this part:
$req = mysql_query('select password,id from users where username="'.$username.'"');
$dn = mysql_fetch_array($req);
if($dn['password']==sha1($password) and mysql_num_rows($req)>0)
{
$form = false;
$_SESSION['username'] = $_POST['username'];
$_SESSION['userid'] = $dn['id'];
You need to also select the acc_type. ASSUMING it's a field in the users table, modify the query to read this:
'select password,id, acc_type from users where username="'.$username.'"'
Then make sure to set the session var:
$form = false;
$_SESSION['username'] = $_POST['username'];
$_SESSION['userid'] = $dn['id'];
$_SESSION['acc_type'] = $dn['acc_type'];
When you test this, make sure you log out then log bacak in again.

Joomla 1.5 Call for get_path('admin_html') returning Null

On line 18 of the admin.categories.php file there is
require_once( JApplicationHelper::getPath( 'admin_html' ) );
The Helper Library file has not been modified, it still reads
function getPath( $varname, $user_option=null )
$check = ( ( $varname == 'mod0_xml' ) || ( $varname == 'mod1_xml' ) );
if ( !$user_option && !$check ) {
$user_option = JRequest::getCmd('option');
} else {
$user_option = JFilterInput::clean($user_option, 'path');
}
$result = null;
$name = substr( $user_option, 4 );
...
case 'admin_html':
$path = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.html.php';
$result = JApplicationHelper::_checkPath( $path, -1 );
break;
So it's going to wind up building a path '/components//admin..html.php' because the $name and $user_option variables are both empty, right? Then the checkpath fails, which returns null during a failure. None of this code has been modified to my knowledge. So what gives? Anyone point me in the right direction?
The problem this causes is that it throws a fatal error when it can't open a required file. So I can't open the category manager.
So when you select Category Manager from the Content menu getPath() is called with $varname == 'admin_html' and $user_option == null.
That means that as the first if() is true (because null equates to false and $check is false) $user_option gets set to com_categories (the result of the JRequest::getCmd('option'); line)
Then $name gets set to 'categories', so when the switch() get to the admin_html case it is setting $path to /components/com_categories/admin.categories.html.php (assuming the local directory separator is set to / ).
So as that is the right path and that file is normally included on a J1.5 installation something else has gone wrong (or the file has been removed/deleted)

Resources