justAnoob Posted May 23, 2009 Share Posted May 23, 2009 I have a URL that changes depending on the page number,, like so... http://www.--------/-------.php?pageno=2 Is there a way to get the URL and put it in a variable so I can use that variable in a header statement header("location: http://www.---------.com/--------.php?$variable"); something like that Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/ Share on other sites More sharing options...
cunoodle2 Posted May 23, 2009 Share Posted May 23, 2009 Can't you just do this.. <?php $pageno = isSet($_REQUEST['pageno']) ? $_REQUEST['pageno'] : NULL; header("location: http://www.---------.com/--------.php?$pageno"); ?> Or am I not understanding your question. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840516 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 I'll give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840522 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 my page number is already setup through a pagination that I have through a script that displays the pictures... I'm just looking to get the URL and put it as a variable.... Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840540 Share on other sites More sharing options...
Ken2k7 Posted May 23, 2009 Share Posted May 23, 2009 You mean the entire URL? Which part specifically? If I read you correctly, I think you want this - $page = isset($_GET['pageno'])? intval($_GET['pageno']) : 0; header('Location: ' . $_SERVER['PHP_SELF'] . '?pageno=' . $page); Right? Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840542 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Something like that,,, but the progress bar on the bottom of my browser slowing gets to 100%,, really really slow.. and then does nothing. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840547 Share on other sites More sharing options...
Masna Posted May 23, 2009 Share Posted May 23, 2009 Something like that,,, but the progress bar on the bottom of my browser slowing gets to 100%,, really really slow.. and then does nothing. Lol, because you're infinitely redirecting. If you just keep calling to the Location header and redirecting to the page you're already on every time it loads, immediately, the page will just keep refreshing over and over again. You need to call to the Location header only in specific cases. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840549 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Again,,, All I want is to get the URL,, save it as a variable so I can use that in my header statement... The reason being is that lets say I have 10 pages with pictures.... And a user modifies a picture on page 6,, after the modification,, it takes the user back to to original page.... original page http://www.---------.com/-------.php page with whatever page there on http://www.--------.com/--------.php?pageno=2 Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840552 Share on other sites More sharing options...
Masna Posted May 23, 2009 Share Posted May 23, 2009 On the page before the page on which a user modifies a picture, store the current page in a session variable: $_SESSION['last_page'] = $_SERVER['PHP_SELF']; Then, on the page on which a user actually modifies a picture, after the modification is complete, call to header like this: header("Location: ".$_SESSION['last_page']); Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840554 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 It says that my browser cannot display that web page. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840555 Share on other sites More sharing options...
BK87 Posted May 23, 2009 Share Posted May 23, 2009 during the modification proccess... why not make a hidden form? with $_SERVER["HTTP_REFERER"] (hope I spelled it right) Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840556 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Starting to get confused,,, though this would be easier. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840558 Share on other sites More sharing options...
BK87 Posted May 23, 2009 Share Posted May 23, 2009 dude lol easy stuff here lol okay. user click a link to edit image or something right? so... <form action=save.php method=post> <input type=hidden name=url value="<?= $_SERVER["HTTP_REFERER"]; ?>"> more input forms or w/e... <input type=submit> </form> save.php should have <? //code for saving changes to your image modifications... then header("Location: ".$_POST["url"]); die; ?> end of story also by you saying original page, do you mean page 1 or the page 6 that user was on? Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840559 Share on other sites More sharing options...
BK87 Posted May 23, 2009 Share Posted May 23, 2009 the only down site to that, is if user accesses the edit page without going to the "paging" system it will screw things up... so maybe you'd want to make a check to see if they actually came from looking at pictures in the first place, rather than entering it in the url Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840560 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Alright,, I try this again,, I know its hard for someone when its not right in front of them... I have a page called.. http://www.mypage.com/mypage.php that is displayed with the users first picture. When they click the link to see there second picture.. the url shows. http://www.mypage.com/mypage.php?pageno=2... when the user clicks the link to go back to the first picture.. the url shows... http://www.tradekrazy.com/mytrades.php?pageno=1...... Each page gives the user the ability to update the picture and the name(which works great) but when they change something on page 2,, the browser will refresh and go back to http://www.mypage.com/mypage.php..... I would like it to go back to the page that they were on so they can instantly see the change that was made instead of going through the pages to find what they changed... I hope you understand this... Maybe you already did, and I'm not understanding what everyone was trying to tell me. Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840568 Share on other sites More sharing options...
redarrow Posted May 23, 2009 Share Posted May 23, 2009 post the full code because you need to say something like. if(isset($_POST['save'])){ refresh page and show current page. //example only. //header("location: {$_SERVER['PHP_SELF']}?num={$_GET['num']}") Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840570 Share on other sites More sharing options...
BK87 Posted May 23, 2009 Share Posted May 23, 2009 please post some real code, we could debug and help... you probably have a small issue and your are making it into a larger problem Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840573 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Here is the form with the script that shows the users pictures with the pagination integrated into it. <form id="form2" name="form2" method="post" action="updatepicture.php"> <?php session_start(); include "connection.php"; if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } $findit = $_SESSION['id']; $result = mysql_query("SELECT id FROM members WHERE username = '$findit' LIMIT 1"); $e_row = mysql_fetch_assoc($result); $query = mysql_query("SELECT count(*) FROM abcxyz WHERE user_id = " . $e_row['id']) or die(mysql_error()); $query_data = mysql_fetch_row($query); $numrows = $query_data[0]; $rows_per_page = 1; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; $prevpage = $pageno-1; $nextpage = $pageno+1; if ($pageno > $lastpage) { $pageno = $lastpage; } if ($pageno < 1) { $pageno = 1; } $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $sql = mysql_query("SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM abcxyz WHERE user_id = " . $e_row['id'] . " $limit"); $_SESSION['rid_of_delete_button'] = $lastpage; if($lastpage != 0) { echo "<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>"; while ($row = mysql_fetch_array($sql)) { echo "<tr><td width='188' height='180'><div align='center'>"; echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; if(empty($row['imgpath2'])) { echo '<div align="center"><a href="picture2.php"><img src="images/uploadanother.png" border="0"></a></div>'; } else { if(empty($row['imgpath2'])) { echo ""; } else { echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" /><a href="delete_image2.php"><font color="red"> X</a>'; } } echo "</div></td><td width='188'><div align='center'>"; if((empty($row['imgpath3'])) and (!empty($row['imgpath2']))) { echo '<div align="center"><a href="picture3.php"><img src="images/uploadanother.png" border="0"></a></div>'; } else { if(empty($row['imgpath3'])) { echo ""; } else { echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" /><a href="delete_image3.php"><font color="red"> X</a>'; } } echo "</div></td><td width='188'><div align='center'>"; if( (empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) ) { echo '<div align="center"><a href="picture4.php"><img src="images/uploadanother.png" border="0"></a></div>'; } else { if(empty($row['imgpath4'])) { echo ""; } else { echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" /><a href="delete_image4.php"><font color="red"> X</a>'; } } echo "</div></td><td width='190'><div align='center'>"; if( (empty($row['imgpath5'])) and (!empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) ) { echo '<div align="center"><a href="picture5.php"><img src="images/uploadanother.png" border="0"></a></div>'; } else { if(empty($row['imgpath5'])) { echo ""; } else { echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" /><a href="delete_image5.php"><font color="red"> X</a>'; } } echo "</div></td></tr><tr><td height='43' colspan='4'>"; echo '<strong>Item Name:</strong> <input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" /> '; if ($pageno == 1) { echo " Previous Item "; } else { echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'> Previous Item </a>"; } echo "($pageno of $lastpage)"; if ( $pageno == $lastpage ) { echo " Next Item "; } else { echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'> Next Item </a>"; } echo "</td><td><div align='center'>"; echo '<input type="hidden" name="id" value="' . $row['id'] . '" size="25" />'; echo "</div></td></tr><tr><td height='116' colspan='4'>"; echo '<strong>Description:</strong> <textarea name="description" cols="75" rows="5">' . $row['description'] . '</textarea>'; echo "</td><td><div align='center'>"; echo '<input type="submit" name="submit" id="submit" value="Update Item">'; echo "</div></td></tr><tr><td height='124' colspan='4'>"; echo '<strong>Seeking:</strong> <textarea name="in_return" cols="75" rows="5">' . $row['in_return'] . ' </textarea>'; echo "</td><td><div align='center'>"; if(isset($_SESSION['updatecomplete'])) { unset($_SESSION['updateerror']); echo $_SESSION['updatecomplete']; } if(isset($_SESSION['updateerror'])) { unset($_SESSION['updatecomplete']); echo $_SESSION['updateerror']; } if(isset($_SESSION['picupload'])) { unset($_SESSION['updatecomplete']); unset($_SESSION['updateerror']); echo $_SESSION['picupload']; } echo "</div></td></tr><tr><td colspan='4'>"; echo '<input type="hidden" name="category" value="' . $row['category'] . '" size="25" />'; //echo "</td><td><div align='center'>"; //echo ''; echo "</td></tr>"; $_SESSION['move_id'] = $row['id']; $_SESSION['move_category'] = $row['category']; $_SESSION['path_1'] = $row['imgpath']; $_SESSION['path_2'] = $row['imgpath2']; $_SESSION['path_3'] = $row['imgpath3']; $_SESSION['path_4'] = $row['imgpath4']; $_SESSION['path_5'] = $row['imgpath5']; } echo "</table>"; } else { echo '<div align="center">You currently have no items.<br />Post your first item now!</div>'; } ?> </form> When a user deletes an image... this script does just that... <?php //error_reporting(E_ALL); //ini_set('display_errors',1); session_start(); require 'connection.php'; $id_gone = $_SESSION['move_id']; $image2 = $_SESSION['path_2']; $empty = ""; unlink($image2); $sql = "UPDATE abcxyz SET imgpath2 = '$empty' WHERE id = '$id_gone'"; if(mysql_query($sql)) { header("location: http://www.mypage.com/mypage.php"); // This should have a something refering to what page they were on. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840578 Share on other sites More sharing options...
justAnoob Posted May 23, 2009 Author Share Posted May 23, 2009 Tough crowd at 4 in the morning. No one has chimed in yet,,, any input? Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840823 Share on other sites More sharing options...
Ken2k7 Posted May 24, 2009 Share Posted May 24, 2009 Do you need to keep so many of those $_SESSIONs? But anyways, add a hidden field to the form and use $_POST['pageid'] or whatever to get it. Then tack it on the URL. Easy? Quote Link to comment https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840979 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.