Jump to content

Php Reload Script


ki

Recommended Posts

I have a problem with one of my codes. It works in google chrome but not in safari which I don't understand since it's mostly a server side script.

 

What I'm doing is creating a session and on the page where it's redirecting it's suppose to create a script to call a javascript function which works in Chrome. I don't understand what the problem is at all since I see it work in Chrome but not Safari.

 

This is the redirect script:

<?php
if (!$_POST['image-upload-post']) {
$_SESSION['upload'] = 1;
header("Location: index.php");
}
?>

 

This is the script on the page it's going to:

if($_SESSION['upload']==1) {
 print("<script type=\"text/javascript\">upload();</script>");
 $_SESSION['upload'] = 0;
} else { }

Link to comment
Share on other sites

A) You need an exit; statement after your header() redirect to prevent the remainder of the logic on your page from running while the browser performs the redirect.

 

B) Are you sure $_POST['image-upload-post'] exists? If you are using an image for a submit button or your form is invalid html, it might not exist in some browsers.

Edited by PFMaBiSmAd
Link to comment
Share on other sites

A) You need an exit; statement after your header() redirect to prevent the remainder of the logic on your page from running while the browser performs the redirect.

 

B) Are you sure $_POST['image-upload-post'] exists? If you are using an image for a submit button or your form is invalid html, it might not exist in some browsers.

I have nothing else after the header at this point, it's honestly just the code shown that's in that file. As for the POST, it is valid and it is working. I want anyone who hasn't tried posting anything that goes to that direct URL to go to the main page and display the Popup!

Edited by ki
Link to comment
Share on other sites

I have nothing else after the header at this point,
You need a die after your header regardless, and remove your ?> tag, if there's whitespace after it it could screw up other header code.

 

As for the POST, it is valid and it is working
You've verified that this specific post value exists in all browsers?
Link to comment
Share on other sites

You say it isn't working, but what does that mean - exactly? Is the page getting directed and you just aren't getting the popup (which would seem to indicate a JS problem) or is it not getting redirected at all?

 

You also say that the code you provided for the first page is the entirety of the code for that page. Where's the session_start() statement? Also, wouldn't you want to unset that session value after echoing the javascript code?

Link to comment
Share on other sites

You need a die after your header regardless, and remove your ?> tag, if there's whitespace after it it could screw up other header code.

 

You've verified that this specific post value exists in all browsers?

I did the die and yes I have verified the post.

 

You say it isn't working, but what does that mean - exactly? Is the page getting directed and you just aren't getting the popup (which would seem to indicate a JS problem) or is it not getting redirected at all?

 

You also say that the code you provided for the first page is the entirety of the code for that page. Where's the session_start() statement? Also, wouldn't you want to unset that session value after echoing the javascript code?

I mean the page isn't calling the Javascript function. I've stumbled upon something while checking to see if it was maybe the session and it appears it isn't. I added another print function displaying some random string of text and it works. And I just changed the code around to where there's a inclusion of a php file which holds the session info.

 

<?php
if($_SESSION['upload'] == 1) {
 print("<div style=\"display:none;\">test</div>");
 print("<script type=\"text/javascript\">upload();</script>");
 $_SESSION['upload'] = 0;
} else { }
?>

 

That's the code that works. I don't know why it works with a print that's actually displaying text and not the other. I would just say this is working but I'm pretty anal about that.

Link to comment
Share on other sites

Now you're just...not making any sense.

 

What I've learned so far:

 

1) The code you post is not your code, there is other code that we're not seeing. This right here means you can't be helped.

 

2) "Not working" means that in certain browsers a javascript function ("upload") isn't being called.

 

3) You can print a DIV but not a script tag in the line right after it? Or maybe you mean everything is printing just fine and this is a javascript problem? Or...maybe?

 

What's the current state? Both of these print statements are working as designed and specific browsers aren't executing the function? The print statements only work when there's two of them, regardless of browser? What's happening?

Link to comment
Share on other sites

You say it isn't working, but what does that mean - exactly? Is the page getting directed and you just aren't getting the popup (which would seem to indicate a JS problem) or is it not getting redirected at all?

 

You also say that the code you provided for the first page is the entirety of the code for that page. Where's the session_start() statement? Also, wouldn't you want to unset that session value after echoing the javascript code?

 

I mean the page isn't calling the Javascript function. I've stumbled upon something while checking to see if it was maybe the session and it appears it isn't. I added another print function displaying some random string of text and it works. And I just changed the code around to where there's a inclusion of a php file which holds the session info.

 

You need to check HTML source to see if the line of JS code was written to the page or not. If so, then this is a JS issue. If not, then the if() condition is returning false. Again, I go back to why is there no session_start() in the code for the first page.

Link to comment
Share on other sites

Okay here I'll show you most of the code there is:

 

upload.php

<?php
include("index_cross_session.inc.php");
if (!$_POST['image-upload-post']) {
$_SESSION['upload'] = 1;
header("Location: index.php");
die;
}
?>

 

index_cross_session.php

<?php
session_start();
 if (!$_SESSION['id']) { $_SESSION['id'] = hash(crc32,uniqid()); session_write_close(); }
?>

 

index_header.php

<?php
include("index_cross_session.inc.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link media="screen" rel="stylesheet" href="tragical.css" />
<link media="screen" rel="stylesheet" href="colorbox.css" />
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="jquery.colorbox-min.js" type="text/javascript"></script>
<script src="tragical.js" type="text/javascript"></script>
<?php
if($_SESSION['upload'] == 1) {
 //print("<div style=\"display:none;\">LOL</div>");
 print("<script type=\"text/javascript\">upload();</script>\n");
 $_SESSION['upload'] = 0;
} else { }
?>

Link to comment
Share on other sites

In this code:

 

<?php
include("index_cross_session.inc.php");
if (!$_POST['image-upload-post']) {
$_SESSION['upload'] = 1;
header("Location: index.php");
die;
}
?>

 

You attempt to write session data, but you closed the session data for writing with the "session_write_close" in your include file. That is something you should look into :)

Edited by premiso
Link to comment
Share on other sites

In this code:

 

<?php
include("index_cross_session.inc.php");
if (!$_POST['image-upload-post']) {
$_SESSION['upload'] = 1;
header("Location: index.php");
die;
}
?>

 

You attempt to write session data, but you closed the session data for writing with the "session_write_close" in your include file. That is something you should look into :)

nope, that didn't work. the code shows up only if I print() twice, the session I don't think is the problem.

Link to comment
Share on other sites

So when I view source on the targeted upload.php page form the browser, the header redirects it to the index.php where it's displaying the <script> code which is calling the upload script I require but when I load the page it doesn't call. So my script is working, there is a javascript problem I guess? I don't know what the hell to do.

Link to comment
Share on other sites

I fixed it. I ended up putting the code in the body, like this:

 

<body<?php if($_SESSION['upload'] == 1) { print(" onload=\"javascript: upload();\""); $_SESSION['upload'] = 0; } else { } ?>>

 

thanks for all the help guys

Link to comment
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.