window.location.replace() creates unwanted double quote - javascript

I am getting a strange double quote inserted into my HTML from my PHP script. I have tried all I know to prevent it but am at a loss'
Here is the code
<?php
$Client_number =$_GET['client_number'];
$update_type =$_GET['input_type'];
$class_no = $_POST['class_name_sel'];
echo '<div class ="enter_stu_info">';
echo '<h2>Creating the following student records</h2>';
if ($update_type == "reg")
{
require_once('../connections/i_connect.php');
$stu_line_count = 1;
$stu_temp = ($_POST['stu_first_name_'.$stu_line_count]);
while($stu_temp!= ""){
$first_name = $_POST['stu_first_name_'.$stu_line_count];
$stu_surname = $_POST['stu_last_name_'.$stu_line_count];
$employer_number =$_GET['client_number'];
$reg_stu_query = mysqli_query($i_connect, "INSERT INTO is_student(first_name, last_name, class_no, employer) VALUES('$first_name', '$stu_surname', '$class_no','$employer_number')");
echo 'First Name: '.$first_name.' Last name:'.$stu_surname.' Class_number: '.$class_no.' Client_number: '.$employer_number.' ';
$stu_line_count++;
$stu_temp = ($_POST['stu_first_name_'.$stu_line_count]);
}
if ($reg_stu_query){echo ' <h3>Entered</h3><br/>';}
}
if ($update_type == "blank_stu")
{
require_once('../connections/i_connect.php');
$no_of_students = $_POST['no_of_students'];
$stu_line_count = 1;
$employer_number =$_GET['client_number'];
while($stu_line_count <= $no_of_students){
$is_entered = mysqli_query($i_connect, "INSERT INTO is_student(class_no, employer) VALUES('$class_no', '$employer_number')");
echo ' Class_number: '.$class_no.' Client_number: '.$employer_number.' Student number: '.$stu_line_count;
if ($is_entered == "true"){echo ' <h3>Entered</h3>';}
echo'<br/>';
$stu_line_count++;
}
}
$win_loc_txt = '"create_student_enter.php?client_number='.$employer_number.'&class_no='.$class_no.'"';
echo'<br/>'.$win_loc_txt.'<br/>';
echo '<input name="more_stu_button" type="button" onClick="window.location.replace('.$win_loc_txt.')" value="Add more students">';
echo '</div>';
?>
This gives me the following result(note the unwanted double quote in the "window.location.replace() script between the "client_number=" and the "7" even though the echo of the variable used does not show the unwanted quotation mark..
<!DOCTYPE html>
<html>
<head>
<body>
<div class="enter_stu_info">
<h2>Creating the following student records</h2>
First Name: testing Last name:testing Class_number: 1 Client_number: 7
<h3>Entered</h3>
<br>
<br>
"create_student_enter.php?client_number=7&class_no=1"
<br>
<input name="more_stu_button" onclick="window.location.replace(" create_student_enter.php?client_number="7&class_no=1")"" value="Add more students" type="button">
</div>
<script type="text/javascript" language="javascript">
</body>

You're getting it because you're putting it there:
$win_loc_txt = '"create[...snip..] .'"';
^--------------------^
echo '<input [..snip..] onclick="window.location.replace('.$win_loc_txt.')" value= [..snip..]
When you put them together:
echo '<input [..snip..] onclick="window.location.replace("create...");" value=[.snip..]
^------------------------^ ^--unknown/illegal attribute
Since you're prematurely terminating your onclick attribute, the browser is forced to try and GUESS what you intended and fix things as best it can.
You're dumping text from PHP directly into a Javascript context, inside an HTMl attribute, which means you have to generate valid javascript AND html, simultaneously.
Try something like
echo '<input ...' . htmlspecialchars(json_encode($win_loc_text)) . '...';
instead.

The issue was that you were using " within a ", so your code should really be:
<!DOCTYPE html>
<html>
<body>
<div class="enter_stu_info">
<h2>Creating the following student records</h2>
First Name: testing Last name:testing Class_number: 1 Client_number: 7
<h3>Entered</h3>
<br>
<br>
"create_student_enter.php?client_number=7&class_no=1"
<br>
<input name="more_stu_button" onclick="window.location.replace(' create_student_enter.php?client_number=7&class_no=1');" value="Add more students" type="button">
</div>
<script type="text/javascript" language="javascript">
</body>

Related

Javascript Uncaught SyntaxError: Unexpected token

I am having issues calling my javascript function which loops through an array calling an external PHP page for each value. I get the following error in my developer console in Chrome:
Uncaught SyntaxError: Unexpected token . CSV.php?reg=1:3
When inspecting my values passing to the script everything is there as it should be:
<script type="text/javascript">
function.csvgen(){
var area = "["22","23","24"]";
var start =""2017-01-30"";
var end = ""2017-02-06"";
var len = area.length;
for (i = 0; i < len; i++) {
$.getScript("CSVGEN.php?area="+area[i]+"&start="+start+"&end="+end);
}
}
</script>
I'm not exactly a good programmer and have used very little Javascript (which required assistance from this wonderful forum as well...). Here is my code for the page. The point of the code is to let the user select a number of areas based on their region as well as a start date and an end date and then generate a CSV from my MS SQL database for each, the code for which is in the called CSVGEN.PHP file. I've tested the CSVGen file with a manually generated link and it works, it does not if I put the static link inside the for loop.
<script type="text/javascript">
function.csvgen(){
var area = "<?php echo json_encode(array_values($_POST['arealist'])); ?>";
var start ="<?php echo json_encode($_POST['start']); ?>";
var end = "<?php echo json_encode($_POST['end']); ?>";
var len = area.length;
for (i = 0; i < len; i++) {
$.getScript("CSVGEN.php?area="+area[i]+"&start="+start+"&end="+end);
}
}
</script>
<?php
$page_title="CSV Generator";
include("\Include\header.inc");
include("\Include\connect-db.php");
include("\Include\CSVGen.php");
$error="";
$start_date=date("Y-m-d");
$end_date=date("Y-m-d", strtotime("+7 days"));
if(isset($_GET['reg']))
{
$reg=$_GET['reg'];
}
else{
$reg='1';
}
if($start_date>$end_date){
$error = 'ERROR: End Date cannot be before Start Date!';
}
if ($error != '')
{
echo '<div class="container">
<div class="row">
<div class="alert alert-danger col-md-12">'.$error.'
</div>
</div>
</div>';
}
$sqlareas="SELECT Area_Name, Region_ID, Area_ID FROM Listings_Areas WHERE region = '$reg'";
$arearesult= sqlsrv_query($conn, $sqlareas, array(), array("Scrollable"=>"buffered"));
$areacount = sqlsrv_num_rows($arearesult);
function renderForm($arearesult, $areacount, $start_date, $end_date){
?>
<html>
<head>
</head>
<body>
<div class="container">
<div class="row">
<form id="CSV" name="form1" method="post">
<div class="col-md-2 col-md-offset-1">
<p><select name="arealist[]" size="<?php echo $areacount ;?>" multiple="multiple" tabindex="1">
<?php
while($areas=sqlsrv_fetch_array($arearesult)){
echo'<option value="' . $areas['Area_ID'] . '">' . $areas['Area_Name'] . '</option>';
}
?>
</select>
</div>
<div class="col-md-3">
<strong>Start Date: </strong> <input type="date" name="start" value="<?php echo $start_date; ?>" />
</div>
<div class="col-md-3">
<strong> End Date: </strong> <input type="date" name="end" value="<?php echo $end_date; ?>" />
</div>
<div class="col-md-2">
<input type="submit" onclick="csvgen()" name="submit" value="Get CSVs">
</div>
</form>
</div>
</div>
<?php
}
if($_SERVER['REQUEST_METHOD'] === 'POST'){
print_r(array_values($_POST['arealist']));
echo $_POST['start'];
echo $_POST['end'];
}
else{
renderForm($arearesult, $areacount, $start_date, $end_date);
}
?>
I've tried removing all tabbing/spacing and clearing any potential illegal characters that might have snuck in, but it's showing a period, which I can only guess is referring to either my area.length which as far as I can tell from the manual is right and I still get the error if I remove it or $.getscript, but I've used that elsewhere in similar functions with no issue so I don't know why that would be wrong, or how to replace it.
At the very begining of the script you have:
<script type="text/javascript">
function.csvgen(){
//...
which should be:
<script type="text/javascript">
function csvgen(){
//...
with a space instead . between function and csvgen.
NOTE: this area = "["22","23","24"]"; is also wrong. Use diferent quotes (like area = '["22","23","24"]';) or escape the inner quotes (like area = "[\"22\",\"23\",\"24\"]";)
Find a good javascript tutorial and learn more about how to declare function in javascript.

Passing a variable (php) between html

I am trying pass a parameter in action tag in form, just the way I am doing in href tag but this isn't working can I know why? or should I just use a href tag in form, will that overwrite action in form?
Here is my code:
<!DOCTYPE html>
<html lang="en">
<?php
$ty=$_GET['param'];
$name=$_GET['param1'];
if($ty=='teacher')
{
$web = "<a href='teacherrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
$blk = "<a href='newblocktryteacher.php?a=$name'>Block this site</a>";
$unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
}
else
{
$web = "<a href='pupilrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
$blk = "<a href='newblocktrypupil.php?a=$name'>Block this site</a>";
$unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site";
}
// $type=$_GET['param2'];
$courseA='A';
$courseB='B';
?>
<body>
<?php echo $rep; ?>
<FORM action = <?php echo $blk; ?> method ="POST";>
Block : <input type ="text" name = "url" /></br>
<br>
<input type="submit" value="block" />
<br>
</FORM>
</body>
</html>
1) As you already creating link based on condition then you can directly echo that variable inside markup. e.g.
<?php echo $rep; ?>
2) Instead of passing html in form action just you pass that script name. e.g
newblocktryteacher.php?a=somename or newblocktrypupil.php?a=somename
Based on these two points your code will be
<!DOCTYPE html>
<html lang="en">
<?php
$ty=$_GET['param'];
$name=$_GET['param1'];
if($ty=='teacher')
{
$web = "<a href='teacherrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
$blk = "newblocktryteacher.php?a=$name";
$unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
}
else
{
$web = "<a href='pupilrepute.php?a=$name'>My repute score</a>";
$rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
$blk = "newblocktrypupil.php?a=$name";
$unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site</a>";
}
// $type=$_GET['param2'];
$courseA='A';
$courseB='B';
?>
<body>
<?php echo $rep; ?>
<form action="<?php echo $blk; ?>" method="POST">
Block : <input type="text" name="url" /></br>
<br>
<input type="submit" value="block" />
<br>
</form>
</body>
</html>
Your $blk isn't formatted in a way proper for <form>:
$blk = "<a href='newblocktryteacher.php?a=$name'>Block this site</a>";
<FORM action = <?php echo $blk; ?> method ="POST";>
Assuming $name is bob in this example:
<FORM action = <a href='newblocktryteacher.php?a=bob'>Block this site</a> method ="POST";>
As you can see, this is not correct. All you need is the URL itself. Also, remove the semicolon after "POST".
Your $blk is not a valid action form, because it's a <a> tag(link). So, $blk should be newblocktrypupil.php?a=$name' instead.

can I get text from html and put it into variable in php without submitting a form?

I have a form in html:
<form>
<label><input type="hidden" name="pNameChange" value=""></label>
</form>
and I want to get the value of this input in php without submitting it in a form.
this is my javascript:
var pName= null;
$(document).ready(function(){
$('img').click(function(){
pName= $(this).attr("name");
console.log(pName);
});
});
My php:
$pName = isset($_POST['pNameChange']) ? $_POST['value'] : '';
what I want is. you click on the picture,
1.the value of the name attribute of the picture is going to be saved into the variable pName (javascript),
2.it then goes into the form and changes the value of the form to the variable pName (javascript),
3.php picks up the value of the form (which should now be equal to pName),
4.then stores it into a variable $pName (php).
5.I also want $pName (php) to be globally used throughout all the pages of the website.
edit
this is my index page:
<?php
$pName = isset($_POST['pNameChange']) ? $_POST['value'] : '';
$db_connection = mysqli_connect('localhost','root','',"project_online_planner");
if (!$db_connection){
die('Failed to connect to MySql:'.mysql_error());
}
$query="SELECT * FROM project limit 5 ";
$results = mysqli_query($db_connection,$query);
$intro=mysqli_fetch_assoc($results);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Project planner online</title>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="ppo.js"></script>
<link rel="stylesheet" href="ppo.css"/>
</head>
<body>
<div id="bgNav">
<div id="login">
Register
Log in
</div>
<nav id="nav">
Home
</nav>
</div>
<h2 class="titlePage">Home</h2>
<div id="bgTile">
<?php
while($row = mysqli_fetch_array($results))
{
$project = $row["name"];
echo nl2br("<a href='project.php'>" ."<img name=\"$project\" width='100px' alt='Procject name' height='100px' class='tile' src=". $row['image'] ."/>". "</a>");
}
?>
<div class="tile" id="tileM"><h2>Meer</h2></div>
</div>
<form>
<label><input type="hidden" name="pNameChange" value=""></label>
</form>
</body>
</html>
what I want: click on the image then you get sent to the project page where (php) $pName is equal to the value of (javascript) pName
project page:
<?php
$newRecord = null;
$pName = isset($_POST['pNameChange']) ? $_POST['value'] : '';
$db_connection = mysqli_connect('localhost','root','',"project_online_planner");
if (!$db_connection){
die('Failed to connect to MySql:'.mysql_error());
}
//insert into database
if(isset($_POST['insertComments'])){
include('connect-mysql.php');
$username = $_POST['username'];
$comment = $_POST['comment'];
$sqlinsert = "INSERT INTO user_comments (username, comment, project) VALUES ('$username', '$comment', '$pName')";
if (!mysqli_query($db_connection, $sqlinsert)){
die('error inserting new record');
}
else{
$newRecord = "1 record added";
}//end nested statement
}
//text from database
$query="SELECT * FROM user_comments where project = '$pName' ";
$results = mysqli_query($db_connection,$query);
$intro=mysqli_fetch_assoc($results);
$query2="SELECT * FROM project where name = '$pName' ";
$results2 = mysqli_query($db_connection,$query2);
$intro2=mysqli_fetch_assoc($results2);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Project planner online</title>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="ppo.js"></script>
<link rel="stylesheet" href="ppo.css"/>
</head>
<body>
<div id="intro">
</div>
<div id="bgNav">
<nav id="nav">
Home
<a class="rightNav" href="register.php">Register</a>
<a class="rightNav" href="login.php">Log in</a>
</nav>
</div>
<div id="projectTile">
<span id="statusCheck"><?php print_r($intro2["status"]); ?></span>
<h2 id="prTitle"><?php print_r($intro2["name"]); ?></h2>
<div id="prPic"><img width="300" height="200" src="<?php print_r($intro2["image"]); ?>"></div>
<div id="prDescription"><?php print_r($intro2["description"]); ?></div>
</div>
<div id="comments">
<?php
while($row = mysqli_fetch_array($results))
{
echo nl2br("<div class='profile_comments'>" . $row['username'] . "</div>");
echo nl2br("<div class='comment_comments'>" . $row['comment'] . "</div>");
}
?>
</div>
<div id="uploadComments">
<form method="post" action="project.php">
<label for="name"><input type="hidden" name="insertComments" value="true"></label>
<fieldset>
<legend>comment</legend>
<label>Name:<input type="text" id="name" name="username" value=""></label><br/>
<label>Comments: <textarea name="comment" id="comment"></textarea></label>
<input type="submit" value="Submit" id="submitComment">
</fieldset>
</form>
</div>
<?php
echo $newRecord;
?>
<form>
<label><input type="hidden" name="pNameChange" value=""></label>
</form>
</body>
</html>
HTML:
do you have more then 1 image on page? its better if you add ID in image. No need for form and hidden fields for what you want done.
make sure your img has ID like <img id="imageID"...
JavaScript:
var pName= null;
$(document).ready(function(){
$('#imageID').click(function(){
pName= $(this).attr("name");
$.post("project.php", { pNameChange: pName },
function(data) {
// do something here.
});
});
});
above code should work as expected. Now in project.php > $_POST['pNameChange'] should receive the value of pName (image's name attr).
I don't understand what you want when you said $pName available globally on all pages. Please elaborate further, may be look into storing it as cookie/session?
EDIT:
Consider using session to pName value... by simple starting/resuming session in start of file:
<?PHP
session_start();
and then...
to set/update value:
if(isset($_POST["pNameChange"]))
$_SESSION["pName"] = $_POST["pNameChange"];
and then use $_SESSION["pName"] instead of $pName on all pages.
Try Ajax method in jQuery , hope it solves your problem
https://api.jquery.com/jQuery.ajax/
or
https://api.jquery.com/jQuery.post/
Actually, you do not need AJAX for this, all your index.php does it passes the image's name to project.php so try:
In index.php:
<form name='form1' method="post" action='project.php'> <!-- form attributes given -->
<label><input type="hidden" name="pNameChange" value=""></label>
</form>
Javascript:
var pName= null;
$(document).ready(function(){
$('img').click(function(){
//onclick of image, we will save the image name into the hidden input
//and submit the form so that it goes to project.php
$('input[name="pNameChange"]').val($(this).attr("name"));
$('form1').submit()
});
});
And in your project.php:
//now project.php can get the posted value of 'pNameChange'
//There is no input field with `name`->`value`, so $_POST['value'] is invalid.
$pName = isset($_POST['pNameChange']) ? $_POST['pNameChange'] : '';
And if you need this value across multiple pages, global will not work, use sessions.
ok this "additional" answer is to focus on session only. use the codes for client-end from my previous answer and try this on server-end.
index.php Page:
<?php
session_start();
$pName = isset($_SESSION['pNameChange']) ? $_SESSION['pNameChange'] : '';
project.php Page:
<?php
session_start();
$newRecord = null;
$pName = isset($_SESSION['pNameChange']) ? $_SESSION['pNameChange'] : null;
if(is_null($pName) && isset($_POST['pNameChange'])) {
$_SESSION['pNameChange'] = $_POST['pNameChange'];
$pName = $_POST['pNameChange'];
}
hope it helps

search result not showing in the same window

my search result does not show on the same window, i would want the result to be displayed on the same window. i have found the same question but the code is different from what I'm using so i cant relate to it: Search wont show on same page
scenario 1:
if I put in the action="search_result2.php" - it will redirect the result on the other page
scenario 2:
if i used action="" in this code below, its not doing anything
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
$(document).ready(function(){
$("#results").show();
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#search").on('click',function() {
var find = $('#find').val();
var field = $('#field').val();
$.post('search_result2.php',{find:find, field:field}, function(data){
$("#results").html(data);
});
return false;
});
});
</script>
</head>
<body>
<div id="container" style="width:auto">
<div id="mainContent">
<h2>Search</h2>
<form name="search" method="post" action="">
Seach for: <input type="text" name="find" id="find" /> in
<Select NAME="field" id="field">
<Option VALUE="testA">A</option>
<Option VALUE="testB">B</option>
<Option VALUE="testC">C</option>
<Option VALUE="testD">D</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" id="search" value="Search" />
</form>
<div id="results">
</div>
</div>
</div>
</body>
</html>
here is my search_result2.php:
<?php
//This is only displayed if they have submitted the form
if (isset($_POST['searching']) && $_POST['searching'] == "yes")
{
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if (empty($_POST['find']))
{
echo "<p>You forgot to enter a search term";
exit;
}
// Otherwise we connect to our Database
mysql_connect("host", "username", "passw") or die(mysql_error());
mysql_select_db("testdb") or die(mysql_error());
// We preform a bit of filtering
$find = strtoupper($_POST['find']);
$find = strip_tags($_POST['find']);
$find = trim ($_POST['find']);
$field = trim ($_POST['field']);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM testtable WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['testA'];
echo " ";
echo $result['testB'];
echo "<br>";
echo $result['testC'];
echo "<br>";
echo $result['testD'];
echo "<br>";
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
If you want to load in the same page, without refreshing the page, you'll need to make an ajax request.
If you can reload the page, the php part must be in the same "location" as your original link.
For example if you put that code on the top of the same file with the form (and rename it with a .php extension), it should work (if the php can interpret in that folder).

How to create Demo bar for HTML Templates with Next botton and automatic finding folders?

I have some HTML Template and I want show them in iFrame, some of this Template have 2 to 11 colors variety.
folder name ex.
1
2
3
3-1
3-2
3-3
3-4
3-5
4
5
6-1
6-2
7
and more...
I have a botton for show NEXT template.
I want use is_dir in php to check if directory 1 or 3-2 is available then show it.
<?php
$id = $_GET['id'];
$c=$id+1;
$c1=$c."-1";
$xm=$c;
$xm1=$c1;
if (is_dir($xm)) {
$c=$c;
}
if (is_dir($xm1)) {$c=$c1;}
?>
<div id="header-bar">
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="id" value="<?php echo $c ?>">
<input type="submit" value="NEXT">
</form>
</div>
<iframe src="http://barg.ir/demo/<?php echo $id; ?>"></iframe>
Question1: I can show folder 3-1 but I cant show folder 3-2 and 3-3 and..., how do this?
Question2: can coding with php array?
Question3: can coding with JavaScript? what is equal is_dir in javascript?
Why don't you look into using glob()? Put the following into the folder you want to get the information from:
// we'll call it grabber.php
<?php
$files = glob('*', GLOB_ONLYDIR); sort($files, SORT_NATURAL);
?>
// now you can include grabber.php in your form file
<?php
session_start(); include_once 'PATH/grabber.php'; $end = count($files)-1;
<div id='header-bar'>
<form method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
<input type='submit' value='BACK' name='back' />
<input type='submit' value='NEXT' name='next' />
</form>
if(isset($_POST['back'])){
$_SESSION['fileNum']--;
if($_SESSION['fileNum'] < 0)$_SESSION['fileNum'] = $end;
}
elseif(isset($_POST['next'])){
$_SESSION['fileNum']++;
if($_SESSION['fileNum'] > $end)$_SESSION['fileNum'] = 0;
}
else{
$_SESSION['fileNum'] = 0;
}
$f = $files[$_SESSION['fileNum']];
echo " <iframe src='http://barg.ir/demo/$f'></iframe>".
'</div>';
?>
Obviously PATH needs to be changed.
Better yet use JavaScript:
// You'll still need `grabber.php` in the same location as before, only now
// we'll actually make the PHP page into a String for JavaScript usage, like:
<?php
$dirs = glob('*', GLOB_ONLYDIR); sort($dirs, SORT_NATURAL);
$dirsJS = implode("', '", $dirs); // implode into a String for JavaScript Array
echo "//<![CDATA[
var doc = document, bod = doc.body;
bod.className = 'js'; // use .njs class in CSS for users without JavaScript
function E(e){
return doc.getElementById(e);
}
function direct(backId, nextId, iframeId, iframeSrcBase){
var dirs = ['$dirsJS'];
var dl = dirs.length-1, n = 0, f = E(iframeId), s = iframeSrcBase;
f.src = s+dirs[0];
E(backId).onclick = function(){
if(--n < 0)n = dl;
f.src = s+dirs[n];
}
E(nextId).onclick = function(){
if(++n > dl)n = 0;
f.src = s+dirs[n];
}
}
//]]>";
?>
/*
Now back to your main page. I like XHTML, but you can use whatever.
The reason for JavaScript is to avoid scrolling issues and page flashing
This is your main page again without as much PHP. There's no need to
include the other file in PHP, or use a session. We use the `script`
tag instead. Pay attention:
*/
<?php
echo "<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<style type='text/css'>
#import 'yourCSS.css';
</style>
</head>
<body class='njs'>
<div id='header-bar'>
<form method='post' action='{$_SERVER['PHP_SELF']}'>
<input type='button' value='BACK' name='back' id='back' />
<input type='button' value='NEXT' name='next' id='next' />
</form>
<iframe id='ifr' src=''><noscript>Your Browser Does Not Support JavaScript</noscript></iframe>
</div>
<script type='text/javascript' src='PATH/grabber.php'></script>
<script type='text/javascript'>
direct('back', 'next', 'ifr', 'http://barg.ir/demo/');
</script>
</body>
</html>";
?>
Once again, this time in the script tag, change PATH accordingly.

Categories

Resources