Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-24-2006, 08:47 PM   PM User | #1
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
Refreshing using php

Hi all,
I am using a custom made script that im still making and i want to refresh to a page pulled from a mysql db but i want it to refresh a page that stored as a php variable.

Any help welcome,

Thanks
Steven
Webmonkey is offline   Reply With Quote
Old 06-24-2006, 09:04 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Well... technically... refreshing to a different page really isn't refreshing, it's redirecting.

Have you tried just submitting a form using the destination URL in the "onpost"?
Fumigator is offline   Reply With Quote
Old 06-25-2006, 08:42 AM   PM User | #3
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
No, i just want to redirect the user using a value pulled from a mysql database.
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 06-25-2006, 11:44 AM   PM User | #4
cdwhalley.com
New Coder

 
Join Date: Apr 2006
Location: UK
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
cdwhalley.com is an unknown quantity at this point
As long as nothing has been sent to the browser (no HTML, not even any blank spaces before the first <?php) then you can use the header() function to send a user to a different page.
If you have the URL you want to send them to in a variable called $send_url, for example, then the code would be:
PHP Code:
<?php
//NO BLANK SPACES OR HTML BEFORE FIRST TAG!

//Code here...

header("Location: ".$send_url);//Send them to $send_url
?>
__________________
www.cdwhalley.com
cdwhalley.com is offline   Reply With Quote
Old 06-25-2006, 11:56 AM   PM User | #5
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
If something has been redirected to the browser you could use this function which uses HTML to redirect :
PHP Code:
function redirect($url$time){
                echo 
'<meta http-equiv="refresh" content="' $time '; url=' $url '" />';

Mwnciau is offline   Reply With Quote
Old 06-25-2006, 02:02 PM   PM User | #6
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
The thing is when i use a variable it says http://www.steven.com/tutorial/$url cannot be found.
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 06-25-2006, 02:24 PM   PM User | #7
lavinpj1
Regular Coder

 
Join Date: Sep 2005
Posts: 394
Thanks: 1
Thanked 0 Times in 0 Posts
lavinpj1 is an unknown quantity at this point
Paste your code.

~Phil~
lavinpj1 is offline   Reply With Quote
Old 06-25-2006, 02:27 PM   PM User | #8
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
PHP Code:
<?

$user 
"stevengi_tut";
$password "cobra";
$location "localhost";
//only edit location if you have been told to do so.
$db "stevengi_script";
mysql_connect("$location""$user""$password");
mysql_select_db("$db");

// 1. Clean $_GET vars first 
$tutorial = (int) $_GET['tutorial']; 
$select mysql_query("SELECT * FROM tutorials WHERE id = '$tutorial' LIMIT 1");
while(
$row mysql_fetch_array($selectMYSQL_ASSOC)) {
$url2 $row['url2'];
}
        
?>
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 06-25-2006, 02:34 PM   PM User | #9
lavinpj1
Regular Coder

 
Join Date: Sep 2005
Posts: 394
Thanks: 1
Thanked 0 Times in 0 Posts
lavinpj1 is an unknown quantity at this point
There is no redirection code in there.

~Phil~
lavinpj1 is offline   Reply With Quote
Old 06-25-2006, 02:35 PM   PM User | #10
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
well should this work? It doesnt.
PHP Code:
<?

$time 
"2";
$user "stevengi_tut";
$password "cobra";
$location "localhost";
//only edit location if you have been told to do so.
$db "stevengi_script";
mysql_connect("$location""$user""$password");
mysql_select_db("$db");

// 1. Clean $_GET vars first 
$tutorial = (int) $_GET['tutorial']; 
$select mysql_query("SELECT * FROM tutorials WHERE id = '$tutorial' LIMIT 1");
while(
$row mysql_fetch_array($selectMYSQL_ASSOC)) {
$url2 $row['url2'];
echo 
'<meta http-equiv="refresh" content="2; url=. $url .">'
}
        
?>
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 06-25-2006, 02:36 PM   PM User | #11
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
I get:
http://www.stevengibbons.com/tutorial/.%20$url%20.

The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

--------------------------------------------------------------------------------

Please try the following:

If you typed the page address in the Address bar, make sure that it is spelled correctly.

Open the www.stevengibbons.com home page, and then look for links to the information you want.
Click the Back button to try another link.
Click Search to look for information on the Internet.



HTTP 404 - File not found
Internet Explorer
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 06-25-2006, 02:37 PM   PM User | #12
lavinpj1
Regular Coder

 
Join Date: Sep 2005
Posts: 394
Thanks: 1
Thanked 0 Times in 0 Posts
lavinpj1 is an unknown quantity at this point
Well, that is a silly way to do it, but if you insist on it, the line should read...

echo '<meta http-equiv="refresh" content="2; url=' . $url . '">';

The better way to do it would be:

header("Location: " . $url);

Also, your query says $url2, and your redirect line says $url. You need to decide which it is.

~Phil~
lavinpj1 is offline   Reply With Quote
Old 06-25-2006, 02:40 PM   PM User | #13
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
I have fixed both and its still not working and im getting the same error.
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 06-25-2006, 03:03 PM   PM User | #14
lavinpj1
Regular Coder

 
Join Date: Sep 2005
Posts: 394
Thanks: 1
Thanked 0 Times in 0 Posts
lavinpj1 is an unknown quantity at this point
Paste new code.

~Phil~
lavinpj1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:18 AM.


Advertisement
Log in to turn off these ads.