Recent Topics

1 Jan 29, 2007 10:46    

I've this piece of code which sometimes gives the right output and sometimes the number of the blog or some other number.


if ($file=="") {
							echo 'Browsing the Main Page<br />';  
						}
						 
						elseif ($file=="index.php") {
							echo 'Browsing the Main Page<br />';  
						} 
	
						elseif ($file=="articles_stub.php") {
							echo 'Browsing Articles<br />';  
						}
						 elseif ($file=="gems_stub.php") {
							echo 'Browsing the Gems<br />';
						} 
						 elseif ($file=="po_stub.php") {
							echo 'Browsing Poetry<br />';
						} 
						elseif ($file=="q_stub.php") {
							echo 'Browsing Quoations<br />';
						} 
						elseif ($file=="bwb_stub.php") {
							echo 'Browsing A Blog within Blog<br />';
						} 
						elseif ($file=="sel_stub.php") {
							echo 'Browsing Selected Articles by Others<br />';
						} 
						elseif ($file=="link_stub.php") {
							echo 'Browsing Linkblogs<br />';
						} 
						elseif ($file=="about_stub.php") {
							echo 'Browsing About Me!<br />';
						}
						elseif ($file=="gcom_stub.php") {
							echo 'Browsing the general comments<br />';
						}
						elseif ($file=="aboutblog_stub.php") {
							echo 'Browsing About This Blog!<br />';
						}
						else {
							$title=str_replace("_"," ",$file);
							echo '<a class="ext" href="http://www.alkhater.net/blog/index.php/'.$EM[file].'" title=" go to entry: '.ucwords(strtolower($title)).' ">'.ucwords(strtolower($title)).'</a><br />'; 
						}

The names of the stub files are all correct. I've tried to replace if ($file == stub_file) with if ($blog == blog#) but that does not work.

Any ideas!

2 Feb 03, 2007 23:25

The if($file="") is a catch-all ... it all depends on HOW people hit the site. The only thing I can recommend it maybe logging all the variables to a file (so you can find out what you need to do to catch all the ODD ones).

FYI ... I wrote the code in an absolute hurry and know that I haven't caught all the possibilities.

Even on our own site, sometimes the links for "what visitors are reading" go to impossible locations.

3 Feb 04, 2007 04:01

I don't get your idea "The only thing I can recommend it maybe logging all the variables to a file (so you can find out what you need to do to catch all the ODD ones)."

And have you done that for your site and does it work?

I think the best solution would be to strip the URL and get the stub file name only, In that case it would not matter from where the visitor hits the site. I just wish I know how to do that, example:

http://www.alkhater.net/blog/link_stub.php/2007/01/04/p975

strip only the link_stub.php from the URL.

4 Feb 04, 2007 04:35

1/ by "logging the variables", i was meaning (use PHP to append a text file, whereby ALL of the inbound links are logged, so that you would know what all the possible permutations are).

2/ No, I haven't done this for my site, as I'm *happy* with the 80% solution (have a basic knowledge/understanding of how people are hitting the site).

3/ IF you wanted to do that (strip only the link_stup.php from the URL) ... you could do the following:

Assuming they're all of the form you linked:
h t t p ://www.alkhater.net/blog/link_stub.php/2007/01/04/p975

$bits = explode ("/",$theURL);
$yourStrippedLink = $bits[3];

You might want to print_r ($bits); just to be certain, but it seems to me that the part you want would be in the 3rd index in the array. (0=http:, 1=NULL, 2=www.alkhater.net, 3 = link_stub.php [what you want], 4=2007 ... etc.)

Hope this helps

5 Feb 04, 2007 05:05

It seems to work but I need to test it more as more visitors visit different blogs. Here is what I did:

After Line 257 ($file =$EM[file];) I added:


$bits = explode ("/",$theURL);
$yourStrippedLink = $bits[3]; 

And then replaced all the "if statements" with this:


elseif ($yourStrippedLink =="articles_stub.php") {
	echo 'Browsing Articles<br />';  
	}

I'll let you know if it works for all.

Thanks a million.

6 Feb 04, 2007 05:07

In my example, $theURL was an imaginary variable. I won't correspond to anything in the file.

I wasn't 100% certain what the variable was (been ages since I looked at the code), but my guess is that you should change $theURL for $EM[file].

7 Feb 04, 2007 05:13

I don't get that + I don't get what the $EM[] array stores.
It seems that this assignement

$file =$EM[file]

gets the $file (stub_file) and the method you suggested above seem to get it better.

What would it do to change $theURL to $EM[file]?

8 Feb 04, 2007 06:00

So far I got 4 visitors on the same time and they all seem browse the Main Page. This might be true. But your code gave me a little doubt because you use "/" for the $bit and since the URL is http://www.alkhater.net/stub_file/something..

$bit[3] would be www.alkhater.net which will always take you to the main Page.

and not stub_file

Or am I wrong?

9 Feb 04, 2007 06:34

just a note about the code snippet on the first post, you should be using a switch statement for that, and also be using 's instead of "s.

10 Feb 04, 2007 06:38

balupton, you said " and also be using 's instead of "s.

where?

11 Feb 04, 2007 06:46

elseif ($file=="index.php") { 


into

elseif ($file=='index.php') { 


reasonings can be found in the standard coding guidelines page for b2evo and/or in the php tips and tricks topic in the chat away forum.

The ' instead of "s are minor, but the switch statement should of definitely been used there.

12 Feb 04, 2007 08:07

I change "s to 's and I used switch statement like this :


switch(($StrippedLink)
{
case ' ' :
echo 'Browsing the Main Page<br />'; 
break;
						
case 'index.php' :
echo 'Browsing the Main Page<br />';
break;
					 	
case 'articles_stub.php' :
echo 'Browsing Articles<br />';
Break;

...

...
}

but I get the following error which is "{" after the switch.

Parse error: syntax error, unexpected '{' in /home/alkha4/public_html/blog/addOns/visitors/visitors.php on line 301

13 Feb 04, 2007 08:18

You can figure this one out I'm certain! Here's a hint: it wasn't expecting to see that character, so it must be a problem before that character. Take a look at your first line and it'll come to you.

14 Feb 04, 2007 08:31

How stupid can one get. It was the double "((" in the switch statement. I've got to check my code very carefully from now on before I waste the valuable time of good people like you.

15 Feb 04, 2007 09:14

Don't you hate it when little things sneak up and act like monsters in your code? If I had any points left I'd give em to ya!

16 Feb 04, 2007 09:18

Wooohooo i got a big star :D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D

You and Yabba need to stop playing ping pong with your rep points ;)

And don't worry EdB i gave him some points.

Anyway off to the bottleo for me to get some fosters and crown ;) This is a worthwhile celebration right here.

Bow before my unmatchedness!

Ahh we have too much fun nowadays

17 Feb 09, 2007 11:00

Stk, If you look at the SQL statement :


mysql_query('create table Evo_onlineTemp ( ip varchar(40), timestamp integer(15), primary key (timestamp), index(ip) )');
mysql_query('insert into Evo_onlineTemp (ip,timestamp) select ip, max(timestamp) from Evo_online group by ip');
$getEM = mysql_query('select Evo_online.ip, file, totIP, Evo_online.timestamp, Evo_online.init from Evo_online, Evo_onlineTemp where Evo_online.ip=Evo_onlineTemp.ip and Evo_online.timestamp=Evo_onlineTemp.timestamp');

You will see the no field called file. So the line


$file =$EM[file];

does not get anything. So these statements:


$file =$EM[file];
$bits = explode ("/",$file);
$StrippedLink = $bits[3]; 

return "", which means the index.php (the home page).

Please correct me if I'm wrong.

18 Feb 09, 2007 19:16

kskhater wrote:

You will see the no field called file.

Correction: Have a look @ your pma (phpMyAdmin) ;)

If you don't find a field called "file", then please send me a screen copy of your table structure.

19 Feb 09, 2007 20:02

I would of thought it would be because he is using $getEM then he is using $EM, he is using $EM[file] and not $EM['file'] or he simply has not retrieved the values from the mysql result via say mysql_fetch_assoc.

20 Feb 09, 2007 21:16

Sorry stk,

There is a field call "file" in Evo_online but not in Evo_onlineTemp. I took a look at users.php and found where the DB Evo_online is created. But I don't understand why the file should be there since it changes all the time.

The other thing I found there is this code which is siminlar to the code you sent above:


$file = $_SERVER['PHP_SELF'];
$file = explode("/", $file);
$file = $file[2];

Could explain what the first line means?


Form is loading...