AJAX Php ensure page loaded in framework SOLUTION; same using LightWindow; Ajax.Updater OR Ajax.Request ALSO handy $_SERVER['REQUEST_METHOD']=="GET" trick

Wow, I tried a MILLION solutions to this,
and some of them worked...almost...perfectly...
and along the way I learned A LOT,
including some awesome JavaScript and PHP logic, URL sniffers, decision makers, GLOBALS, and so on...
but now, of course, the TRUE solution,
and duh, of course, it's SIMPLE, the SIMPLEST

Scenario, AJAX framework,
loads external pages into a div in the framework,
we don't want said external pages loaded by themselves, that is, their URLs should be visit-able...

Solution:
when AJAX function that loads an external page calls for it,
it also submits with its request a form, or a variable, to the page being loaded in,
page being called looks for that variable,
and without it, follows another line of action,
DUH!

example using Prototype AJAX functions:

AJAX.Updater Version:
button or link on framework base main page calls this function below, sending the variable camefromhome (could be anything), with a value of camefromhome (again, could be anything), requesting that page_to_load be loaded into the div_to_fill div:

<script>
function doit(page_to_load)
{
new Ajax.Updater('div_to_fill', page_to_load,
{
method: 'get',
parameters: { camefromhome:'camefromhome' },
onCreate: load_started_function,
onComplete: load_finished_function
}
);
}
</script>

the page_to_load.php or similar contains this sniffer for sent token variable camefromhome to see if it was called by the framework or NOT! :

<?
if(($_SERVER['REQUEST_METHOD']=="GET")&&($_GET['camefromhome'] == 'camefromhome'))
{
//echo "loaded inside the framework, all clear";
}
else
{
...
}
?>


AJAX.Request Version:
Version that sends a variable with a Lightwindow javascript call and checks as above:

first modify lightwindow.js roughly line 1347 to look something like this:

<script>
_loadWindow : function() {
switch (this.windowType) {

case 'page' :
var pars = 'camefromhome=camefromhome';
var newAJAX = new Ajax.Request(
this.contentToFetch, {
method: 'get',
parameters: pars,
onComplete:
function(response){
$('lightwindow_contents').innerHTML += response.responseText;
this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
this._processWindow();
}.bind(this)
}
);
break;

default : throw("Page Type could not be determined, please amend this lightwindow URL "+this.contentToFetch);
break;
}
}
</script>

then in the document getting loaded in check for the variable being passed or get outta there:

<?
if($_GET['camefromhome']=='camefromhome')
{}
else
{
header('Location:http://www.framework_home.com'); }
?>

Posted on 20 Nov 2009, 16:28 - Category: AJAX
No comments - Edit - Delete


HTML carrots

simple silly entry, but these seem to be in frequent use these days so I need to just be able to grab 'em in a post

&raquo;

also, inject them via CSS, or remove them since they're pesky in Wordpress:

.entry ul li:before, #sidebar ul ul li:before {
/*
content: "\00BB \0020";
*/
}

Posted on 8 Dec 2009, 21:52 - Category: HTML
No comments - Edit - Delete


Wordpress Custom Fields

Need to allow easy entry of a variable in a post and have single.php, page.php, archive.php or otherwise script pick it up?

Use Custom Fields! (wp user admin tool)
Simply add a new custom field Key: named just about anything desired, and the value to pass.
Enter as many as desired, then grab them as an array via the Key name chosen in the script...

$post = $post->ID; // Gets the post's ID
$key = 'ProdId';
$single = false;

$product_list_array = get_post_meta($post, $key, $single);

Bam, Wordpress saves the Key:Value in the database referenced by the post, and the Wordpress function get_post_meta() grabs it back!

Posted on 16 Nov 2009, 11:24 - Category: Wordpress
No comments - Edit - Delete


Php require_once() include_path

//echo get_include_path();

just alter
define('ABS_DOC_ROOT', $_SERVER['DOCUMENT_ROOT'] ."/zendlogin/httpdocs/");

duh, because docroot is different on the server, that's the whole beauty of this

Posted on 5 Nov 2009, 13:37 - Category: Php
No comments - Edit - Delete


Php form isset simple auth login

if (!isset($_POST['email']))
{
}
else
{
{

http://devzone.zend.com/article/646

Posted on 5 Nov 2009, 11:25 - Category: Php
No comments - Edit - Delete


Pages: ... [2] [3] [4] [5] [6] [7] ...
Loading