artworthy Posted May 22, 2009 Share Posted May 22, 2009 what is the function for automatically going to another page on your site or any url for that matter? thanx Quote Link to comment Share on other sites More sharing options...
trq Posted May 22, 2009 Share Posted May 22, 2009 header. Quote Link to comment Share on other sites More sharing options...
artworthy Posted May 22, 2009 Author Share Posted May 22, 2009 I tried : $url="myHome.php" header($url); error returned. What am I missing? Thanx again. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 location $url="myHome.php" header("Location: $url"); EDIT: as a note it is the one of the first example in the php manual for header <?php header("Location: http://www.example.com/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 22, 2009 Share Posted May 22, 2009 If someone posts a link to the manual you should take the time to actualy read it. Quote Link to comment Share on other sites More sharing options...
artworthy Posted May 24, 2009 Author Share Posted May 24, 2009 Still no luck. marked up a login script all lines are working except: $url="http://www.ipingus.com/myFactors.php"; header("Location: $url"); I get on the browser page: Parse error: syntax error, unexpected T_STRING in /hermes/bosweb/web255/b2558/sl.artworthy/public_html/iPingus/scripts/login.php on line 57 (this line is the header() function) Thanks (btw, will read every reply notwithstanding dsl outages) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 well sorry to say this but <?php $url="http://www.ipingus.com/myFactors.php"; header("Location: $url"); ?> works fine! Quote Link to comment Share on other sites More sharing options...
artworthy Posted May 25, 2009 Author Share Posted May 25, 2009 yes, it does work... but not in my script for login. Just have to work on it more. Thanks! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 25, 2009 Share Posted May 25, 2009 see here http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
artworthy Posted May 26, 2009 Author Share Posted May 26, 2009 thanks, but it seems the issue had to do with the db PW not reseting as I thought it did. My hosting service forced a reset. But login script still not doing the job: <?php // logon script if ($_POST['email'] != "") { include_once ('./scripts/connect_to_mysql.php'); $email = $_POST['email']; $pass = $_POST['pass']; $email = strip_tags($email); $pass = strip_tags($pass); $email = mysql_real_escape_string($email); $pass = mysql_real_escape_string($pass); $email = eregi_replace("`", "", $email); $pass = eregi_replace("`", "", $pass); $pass = md5($pass); //make query $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; $mem_name = $row["mem_name"]; session_register('mem_name'); $_SESSION['mem_name'] = $mem_name; $email = $row["email"]; session_register('email'); $_SESSION['email'] = $email; mysql_query("UPDATE members SET last_log_date=now() WHERE id='$id'"); $my_msg = "You're logged on"; header("Location: http://www.ipingus.com/myFactors.php"); print "return_msg=$my_msg&id=$id&mem_name=$mem_name"; } // close while } else { $my_msg = "no_good"; print "return_msg=$my_msg"; exit(); } }// close if post ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 26, 2009 Share Posted May 26, 2009 For starters, session_register has long been depricated and cannot be used in conjunction with the $_SESSION array. Quote Link to comment Share on other sites More sharing options...
corbin Posted May 26, 2009 Share Posted May 26, 2009 This is randomness and me just being picky, but if I remember correctly (this is directed up a couple posts), the Location HTTP header should have a full URL, not just a path relative to the web root of the current site. Or did I dream that at some point... Hrmmm.... Off to google now... Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 26, 2009 Share Posted May 26, 2009 if I remember correctly (this is directed up a couple posts), the Location HTTP header should have a full URL, not just a path relative to the web root of the current site. Your very correct (as always) corbin, most browsers will fix this, and allow you to do it, thats why people (myself included) are lazy and use that shortcut, <?php header("Status: 301"); # 301 Moved Permanently / 302 Temporary moved header("Location: http://{$_SERVER['SERVER_NAME']}/home.php"); exit; ?> As a side note google likes 301 status when things are moved but doesn't like 302 (or thats what i read somewhere..awaits corbin responces lol) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.