Webmonkey 06-24-2006, 08:47 PM 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
Fumigator 06-24-2006, 09:04 PM Well... technically... refreshing to a different page really isn't refreshing, it's redirecting. :D
Have you tried just submitting a form using the destination URL in the "onpost"?
Webmonkey 06-25-2006, 08:42 AM No, i just want to redirect the user using a value pulled from a mysql database.
cdwhalley.com 06-25-2006, 11:44 AM 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() (http://uk.php.net/manual/en/function.header.php) 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
//NO BLANK SPACES OR HTML BEFORE FIRST TAG!
//Code here...
header("Location: ".$send_url);//Send them to $send_url
?>
Mwnciau 06-25-2006, 11:56 AM If something has been redirected to the browser you could use this function which uses HTML to redirect :
function redirect($url, $time){
echo '<meta http-equiv="refresh" content="' . $time . '; url=' . $url . '" />';
}
Webmonkey 06-25-2006, 02:02 PM The thing is when i use a variable it says http://www.steven.com/tutorial/$url cannot be found.
lavinpj1 06-25-2006, 02:24 PM Paste your code.
~Phil~
Webmonkey 06-25-2006, 02:27 PM <?
$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($select, MYSQL_ASSOC)) {
$url2 = $row['url2'];
}
?>
lavinpj1 06-25-2006, 02:34 PM There is no redirection code in there.
~Phil~
Webmonkey 06-25-2006, 02:35 PM well should this work? It doesnt.
<?
$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($select, MYSQL_ASSOC)) {
$url2 = $row['url2'];
echo '<meta http-equiv="refresh" content="2; url=. $url .">';
}
?>
Webmonkey 06-25-2006, 02:36 PM 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
lavinpj1 06-25-2006, 02:37 PM 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~
Webmonkey 06-25-2006, 02:40 PM I have fixed both and its still not working and im getting the same error.
lavinpj1 06-25-2006, 03:03 PM Paste new code.
~Phil~
|
|