Jump to content

Recommended Posts

I don't know if there is a solution to this. I store details in a table of every access to a website. I don't want duiplicates if someone hits F5. In order to do this I set a session variable to detect this. I have also a problem about a variable being passed to the function to store the data.

 

This is the first part of the code in a page.

 

$Page = "Board";

if($_SESSION['current_page'] != "Board" && strlen($_SESSION['current_page'] > 2)
    StoreDataNews($Page); // Problem with passed variable
$_SESSION['current_page'] = "Board";

 

Here the refresh should not work because the session variable is set after storage. The line

StoreDataNews shuld cause the variable to be inserted into the database as it is set 3 lines higher

The function in a seperate file is.

 

function StoreDataNews($Page)
{
  connectDB(1);
  $browser = $_SERVER["HTTP_USER_AGENT"];
  $stamp = time();
  $Date = date('Y-m-d',$stamp);
  $Time = date('H:i:s',$stamp);
  $IP = $_SERVER['REMOTE_ADDR'];

  $sql = "INSERT INTO `NewsLog` VALUES ('','" . $stamp . "','"  . $Date . "','" . $Time . "','" .$IP . "','" . $Page . "','" . $browser . "','" . $hit . "')";

  $query = mysql_query ($sql);
  $result = @mysql_affected_rows($sql);
}

 

The odd behaviour can be seen at entry 39, 41, 44 etc. @

http://www.des-otoole.co.uk/news/stats.php

 

Any sugestions would be a great help.

 

Desmond.

 

 

Link to comment
https://forums.phpfreaks.com/topic/88414-baffled-by-variables/
Share on other sites

I think the problem lies in your if() statement:

 

if($_SESSION['current_page'] != "Board" && strlen($_SESSION['current_page'] > 2)

 

It seems like you've missed off the ) after strlen().  So it should be:

 

if($_SESSION['current_page'] != "Board" && strlen($_SESSION['current_page']) > 2)

 

Give that a try and see what happens.

Link to comment
https://forums.phpfreaks.com/topic/88414-baffled-by-variables/#findComment-452479
Share on other sites

Thanks that sort of helps out but The last bit strlen() was addred to get past the first problem. Why does

 

StoreDataNews($Page); not add $Page into the database when $Page = "Board"; is clearly

set before. There are blanks in the tabel for Page

 

  $sql = "INSERT INTO `NewsLog` VALUES ('','" . $stamp . "','"  . $Date . "','" . $Time . "','" .$IP . "','" . $Page . "','" . $browser . "','" . $hit . "')";

 

 

Link to comment
https://forums.phpfreaks.com/topic/88414-baffled-by-variables/#findComment-452495
Share on other sites

Ok before you do anything else add { } to your if() statement, its a lot easier to see where the statement begins and ends when they're in.

 

As for finding out why $Page doesn't get added, do a bit of debugging first.  Comment out your INSERT line and just try echo-ing $Page and see what you get.

Link to comment
https://forums.phpfreaks.com/topic/88414-baffled-by-variables/#findComment-452559
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.